---
title: "struts2+convertion实现struts.xml的零配置"
author: "qqybh"
date: "2010-08-11T13:58:53Z"
tags: ["Apache", "JSP", "Struts", "Web", "XML"]
categories: ["企业架构"]
slug: "struts2-convertion-struts-xml"
draft: false
lastmod: "2010-08-11T13:58:53Z"
id: 734430
url: "https://qqybh.iteye.com/blog/734430"
---

这几天看了看struts2，有看了一些教程，发现零配置这个思想挺好的，可以简化好多代码！于是就学着做了起来。 struts.xml配置文件 \[code="java"] \[/code] 这里面基本空空， action文件 \[code="java"] package com.song.action; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import com.opensymphony.xwork2.ActionSupport; public class Hello extends ActionSupport { @Override public String execute() throws Exception { // TODO Auto-generated method stub System.out.println("hello this is execute method!"); return SUCCESS; } @Action("showthis") public String mymethod() throws Exception{ System.out.println("-----------------------------------"); return SUCCESS; } } \[/code] 这里面定义了两个方法，然后我再web——info这个目录下，新建了一个jsp文件夹，再里面新建了一个hello.jsp和一个showthis.jsp 之后再浏览器输入http://localhost:8088/test/hello.action,则调用execute方法，然后返回到hello.jsp页面;输入http://localhost:8088/test/showthis.action,则调用mymethod() ，页面跳转到showthis.jsp页面。 注意：一定要导入struts2-convertion-plugs这个jar包，我用的struts2的jar包是2.1版本的