Instantly share code, notes, and snippets.
开发Struts2应用程序-基本步骤
Struts2的工作原理
在Eclipse中配置Struts2第一个HelloWorld项目
YOUKU:北京圣思园struts2深入详解视频
Struts配置: 通过web.xml来声明拦截器
<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>*.action</url-pattern> </filter-mapping>
注意:这里*.action拦截后,只剩下 *。 则.action后缀的访问都会被拦截器拦截进入 struts.xml文件进一步查找。
<package name="gaubee" namespace="/" extends="struts-default"> <action name="gaubeelogin" class="com.gaubee.struts2.LoginAction"> <result name="input">/login.jsp</result> <result name="success">/result.jsp</result> <result name="error">/result.jsp</result> </action> </package>
namespace是用来进一步过滤,好像是struts2.1+才需要这个配置。 就是你网址后的路径,如果namespace="/example" ,则需要多一层/example/gaubeelogin.action 紧接着是action,这里的name不能写成="gaubeelogin.action",因为后缀已经被过滤掉了 class要写对,不然整个网址跑起来后直接报错404,不论哪个页面
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Struts配置:
通过web.xml来声明拦截器
注意:这里*.action拦截后,只剩下 *。
则.action后缀的访问都会被拦截器拦截进入 struts.xml文件进一步查找。
namespace是用来进一步过滤,好像是struts2.1+才需要这个配置。
就是你网址后的路径,如果namespace="/example" ,则需要多一层/example/gaubeelogin.action
紧接着是action,这里的name不能写成="gaubeelogin.action",因为后缀已经被过滤掉了
class要写对,不然整个网址跑起来后直接报错404,不论哪个页面