struts2

mvc:

request-->servlet(based on mapping)-->javabean-->forward to jsp-->response

配置struts2 --web.xml

<web-app>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*<url-pattern>
</filter-mapping>
</web-app>

配置struts--struts.xml

<struts>
<constant name="struts.custom.i18n.resources" value="resoursefile"/>
<constant name="struts.i18n.encoding" value="GBK"/>
</struts>

resourcefile.properties

action

<struts>
<!--所有的action都应该放在package下面-->
<package name="lx" extends="struts-default">
<action name="login" class="x.x.x.LoginAction">
<!--定义三个逻辑视图和物理资源的mapping-->
<result name="input">/login.jsp</result>
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>

prefer convention over configuration

当Action处理用户的请求结束后,通常会返回一个处理结果,我们可以命名该名称为逻辑视图名.这个逻辑视图需要和资源相关联.

如上面的input/error/success都是逻辑视图string.

 

public interface Action{
public static final String ERROR="error";
public static final String INPUT="input";
public static final String LOGIN="login";
public static final String NONE="none";
public static final String SUCCESS="success";
public String execute() throws Exception;
}

 这五个string是用来做execute的返回值!

 

 

 

 

 

 

posted on 2012-09-21 09:25  grep  阅读(264)  评论(0编辑  收藏  举报