struts2是一个框架,这个框架已经为你做好了很多东西,使用时你可以直接调用,也就是你可以把你的关注点放在业务上,不必关心其他东西.
struts.xml是struts2的默认配置文件,在web应用启动之后,会依次加载struts-default.xml,struts-plugin.xml,struts.xml,struts.properties,web.xml,除了struts.xml和web.xml之外其他xml文件可以在struts核心jar文件找到,在这个文件中你可以对acton进行配置,比如你创建了一个HelloworldAction
配置如下:
<package name="hello" namespace="/common" extends="stuts-default">
<acton name="hello" class="某包.HelloworldAction" method="excute">
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
</package>
如果你的jsp上有一个<a href="hello">提交</a>
这段配置的意思就是如果当单击页面时,根据超链接的href属性去找name为hello的Action 找到之后调用了HelloworldAction,并且执行execute方法如果这个方法的返回值是success那么就跳转到">/WEB-INF/page/hello.jsp
public class HellowordAction extends ActionSupport
{
public String execute() throw Exception
{
//这个SUCCESS是ActionSupport中的一个String 常量,你可以看看ActionSupport中的源码
//看了就明白了这里的SUCCESS就是刚才那个result的name属性
return SUCCESS;
}
}
当然你也可以在其中定义拦截器然后在Action中引用,这个struts.xml主要是配置作用告诉应用程序
怎么找Action然后对相应的结果进行处理,
温馨提示:答案为网友推荐,仅供参考