struts.xml文件可以分开写在多个xml文件中。最后通过以下方式导入到struts.xml中即可:
<struts><includefile="my-struts1.xml"/><includefile="my-struts2.xml"/></struts>
struts.properties file
首先struts.properties文件应该放到web-info/classess文件下,我在在这个文件中进行的配置,实际上是重写了struts2-core-x.y.z.jar下的default.properties文件
AcionSupport类实现了Action接口,Action接口中的内容如下:
publicinterfaceAction{publicstaticfinalString SUCCESS ="success";publicstaticfinalString NONE ="none";publicstaticfinalString ERROR ="error";publicstaticfinalString INPUT ="input";publicstaticfinalString LOGIN ="login";publicString execute()throwsException;} 这时候我们就可以把execu个中return返回的字符串如success改为Action中的常量如SUCCESS等 Interceptors(拦截器) 可以在action标签中使用struts2自带的拦截器,如下:
1 |
alias Allows parameters to have different name aliases across requests. |
2 |
checkbox Assists in managing check boxes by adding a parameter value of false for check boxes that are not checked. |
3 |
conversionError Places error information from converting strings to parameter types into the action's field errors. |
4 |
createSession Automatically creates an HTTP session if one does not already exist. |
5 |
debugging Provides several different debugging screens to the developer. |
6 |
execAndWait Sends the user to an intermediary waiting page while the action executes in the background. |
7 |
exception Maps exceptions that are thrown from an action to a result, allowing automatic exception handling via redirection. |
8 |
fileUpload Facilitates easy file uploading. |
9 |
i18n Keeps track of the selected locale during a user's session. |
10 |
logger Provides simple logging by outputting the name of the action being executed. |
11 |
params Sets the request parameters on the action. |
12 |
prepare This is typically used to do pre-processing work, such as setup database connections. |
13 |
profile Allows simple profiling information to be logged for actions. |
14 |
scope Stores and retrieves the action's state in the session or application scope. |
15 |
ServletConfig Provides the action with access to various servlet-based information. |
16 |
timer Provides simple profiling information in the form of how long the action takes to execute. |
17 |
token Checks the action for a valid token to prevent duplicate formsubmission. |
18 |
validation
|
也可以自定义拦截器,自定义拦截器需要实现Inerceptor接口,如下:
publicinterfaceInterceptorextendsSerializable{void destroy();void init();String intercept(ActionInvocation invocation)throwsException; 或者继承不需要init和destory方法的
AbstractInterceptor 类
当创建好了自定义的拦截器类后,在struts.xml中的package标签下通过inteceptor子标签配置一下即可
<struts><constantname="struts.devMode"value="true"/><packagename="helloworld"extends="struts-default"><interceptors><interceptorname="myinterceptor"class="com.tutorialspoint.struts2.MyInterceptor"/></interceptors><actionname="hello"class="com.tutorialspoint.struts2.HelloWorldAction"method="execute"><interceptor-refname="params"/><interceptor-refname="myinterceptor"/><resultname="success">/HelloWorld.jsp</result></action></package></struts>
相关推荐
struts2笔记
黑马程序员Struts2笔记,包括前两天的内容,不包括源码,只是笔记文档
Struts2笔记 本人工作中积累的,故做成笔记以供大家一起学习进步. 模块分的非常详细,各个细节都会关注到,只挑选其精华,工作中用得到的技术!!! 不要看资源小,起到的作用却非常大!!!
这是本人学习Struts2时的笔记,会不断的更新的
非常详细的SSH笔记,Struts2笔记+Hibernate3.6笔记+Spring3笔记,word文档,内容非常详细,可以直接看我的笔记就能轻松学会框架
struts2笔记1
struts2笔记_初步修改版_.struts2笔记_初步修改版_.struts2笔记_初步修改版_.
struts2学习笔记,非本人所写,但有学习的价值,总结的很好,分享一个!
这是学习struts2时记得重点笔记,包括了一些原理,ognl语句的编写,以及如何设置拦截器等等一些基本知识,起到复习和巩固的作用
struts2笔记.doc
struts2笔记和代码,帮助你更容易学习struts2
流行开发框架 struts2笔记 Word文档格式
赵栋的最新struts2笔记,内容详实,也是2013的
里面包含了全面的struts2重点内容,讲解比较详细,希望对大家有帮助吧!
Struts2 笔记12-20 浪曦风中叶