struts2配置文件的解释
1 <?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
//注解:<!-- struts 是struts2配置文件的根元素-->
<struts>
//注解:constant常量配置
<constant name="struts.objectFactory" value="spring" /> //注解:指定struts2默认的objectFactorybean,该属性默认值是spring
<constant name="struts.devMode" value="false" /> //注解:是否使用开发模式,默认为false,测试阶段一般设为true
<constant name="struts.locale" value="zh_GB" /> //注解:<!-- 地区 -->en就是english;GB就是GreatBritain
<constant name="struts.i18n.encoding" value="GBK" /> //注解:指定web应用的默认编码集
<constant name="struts.action.extension" value="action" /> //注解:指定struts2处理请求的后缀名称
<constant name="struts.configuration.xml.reload" value="true" /> //注解:struts.xml文件系统改变后,系统是否重新加载该文件
<constant name="struts.serve.static" value="false" />
//注解:<constant name="struts.serve.static.browserCache " value="false" /> <!-- 当 struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 --> <constant
name="struts.custom.i18n.resources"value="ApplicationResources,errors" />
//注解:指定所需的国际化资源,以逗号分隔,
<constant name="struts.multipart.maxSize" value="2097152" /> //注解:设置上传文件允许的最大字节数
<constant name="struts.multipart.saveDir" value="/resources" /> //注解:设置上传文件所保存的临时文件夹
<constant name="struts.ui.theme" value="css_xhtml" />
//注解:设置主题
<constant name="struts.enable.SlashesInActionNames" value="true" />
//注解:设置Struts 2是否允许在Action名中使用斜线
<package name="login" namespace="/" extends="json-default"> //注解:name:必填,指定包的名字,该名字是该包被其他包引用的key
namespace:可选,定义该包的命名空间。
“/”表示根namespace,所有直接在应用程序上下文环境下的请求(Context)都在这个package中查找
“”表示默认namespace,当所有的namespace中都找不到的时候就在这个namespace中寻找
extends:可选,指定该包继承其他包。继承其他包,可以继承其他包中的Action定义、拦截器定义等
<action name="gotoIndex" class="IndexAction" method="gotoIndex">
//注解:name:请求的action的名称
Class:action处理类对应的具体的路径
Method:指定action中的方法名,如果没有指定method则默认执行action中的execute方法 Converter:指定action使用的类型转换器
<result name="success"> /admin/panel.jsp </result>
<result name="failure"> /login.jsp </result>
</action>
<action name="doFtp" class="IndexAction" method="doFtp"> <result name="success" type="redirect"> gotoIndex.action </result>
//注解:name:对应action返回逻辑视图名称,默认为success,则页面跳转
Type:返回结果类型,默认为dispatcher(请求转发),可以设为redirect(重定向)
<result name="failure"> /login.jsp </result>
</action>
<action name="login" class="LoginAction" method="login"> <result name="success"> /admin/main.jsp </result>
<result name="failure"> /login.jsp </result>
</action>
<action name="logout" class="LoginAction" method="logout"> <result name="success">
/login.jsp </result>
<result name="failure"> /login.jsp </result>
</action>
</package>
请求转发和重定向的区别:
转发和重定向设置:
<action name="deptAction" class="com.syaccp.erp.action.DeptAction">
<result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
<result name="editView">/WEB-INF/jsp/basic/dept_edit.jsp</result>
</action>
上例action中,success对应的视图是通过默认的转发(dispatch)跳转的。editView作为增删改的一部分,应该通过重定向来跳转页面,这样必须显式声明type=redirect,来达到重定向的效果。这时editView的内容改为action中一个方法更合适。如:
<action name="deptAction" class="com.syaccp.erp.action.DeptAction">
<result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
<result name="editView" type="redirect">deptAction!select.action</result>
</action>
这里在执行edit方法后返回editView字符串,将会再执行select方法,跟DeptEditServlet里response.sendRedirect("DeptListServlet")类似
上例只是重定向同一个Action类中的其他方法,开发中可能还需要重定向到其他Action类中,这时就需要用到type属性的另一个值:redirectAction:
<action name="deptAction" class="com.syaccp.erp.action.DeptAction">
<result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
<result name="editView" type="redirect">deptAction!select.action</result>
<result name="index" type="redirectAction">indexAction.action</result>
</action>
上例中,如果deptAction中某个方法返回字符串为index,则将跳转到indexAction去,执行indexAction的execute方法。
如果indexAction在其他包里面,则前面应加上包名,例:index/indexAction
struts2配置文件的解释的更多相关文章
- Struts2 配置文件小结
每次写的博文都被管理员都被移出首页,好气!还希望有哪位大神可以指点迷津-- struts2 配置文件的 result 节点 result 节点是 action 节点的子节点,他代表着 action 方 ...
- Struts2配置文件详解
解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...
- Struts2 配置文件result的name属性和type属性
Struts2 配置文件result的name属性和type属性:Name属性SUCCESS:Action正确的执行完成,返回相应的视图,success是 name属性的默认值: NONE:表示Act ...
- Struts2配置文件模板
<?xml version = "1.0" encoding = "UTF-8"?><!--下面是Struts2配置文件的DTD信息 --&g ...
- Struts2配置文件
Struts2配置文件 简介: 与Struts2相关的配置文件有好几个,常用的有 struts.properties , web.xml, struts.xml等.web.xml中配置Struts2的 ...
- struts2配置文件中action的name属性
struts2配置文件中action的name属性的第一个字符不要加斜杠 <action name="see" class="baoxiuManage_seeAct ...
- Struts2配置文件讲解
解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...
- my.cnf 配置文件参数解释
my.cnf 配置文件参数解释: #*** client options 相关选项 ***# #以下选项会被MySQL客户端应用读取.注意只有MySQL附带的客户端应用程序保证可以读取这段内容.如果你 ...
- 分布式文件存储FastDFS(七)FastDFS配置文件具体解释
配置FastDFS时.改动配置文件是非常重要的一个步骤,理解配置文件里每一项的意义更加重要,所以我參考了大神的帖子,整理了配置文件的解释.原帖例如以下:http://bbs.chinaunix.net ...
随机推荐
- python学习(十六) 测试
测试驱动开发. 16.1 先测试,后编码 16.1.1 精确的需求说明 16.1.2 为改变而计划 16.1.3 测试的4个步骤 16.2 测试工具 16.2.1 doctest 16.2.2 uni ...
- vue-cli脚手架build目录下utils.js工具配置文件详解
此文章用来解释vue-cli脚手架build目录中的utils.js配置文件 此配置文件是vue开发环境的wepack相关配置文件,主要用来处理css-loader和vue-style-loader ...
- Java 查询数据后进行递归操作
java的递归方法记录: private List<Map<String, Object>> generateOrgMapToTree(List<Map<Strin ...
- MySQL备份还原之三使用xtrabackup
1 xtrabackup安装 1)解压源码包 tar -xzvf percona-xtrabackup-2.1.7.tar.gz 2)安装perl环境(DBI/DBD) yum install per ...
- Monthly Expense(二分--最小化最大值)
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the ...
- linux启动lcd屏如水纹状波动,不稳…
开发环境:arm-s3c2416.ubuntu. 内核:linux2.6.26 病症:内核启动时,arm的lcd屏幕出现抖动现象,如水纹状波动,屏幕最下面还有白线闪动,甚至lcd有很多亮点等现象 分析 ...
- 专利系统数据库连接出现 base-64字符串中的无效字符 错误
错误提示如图: 解决方法: 1.进注册表修改如下 2.进入系统配置页面http://10.10.0.70/eaf/init 对数据库进行重新配置 3.若不行再将如下密码修改一下 重启IIS生效
- Nginx 下配置Laravel 错误404
宝塔的访问路径改一下 在站点的配置文件下面server里面加上 location / { try_files $uri $uri/ /index.php?$query_string; } 然后重启Ng ...
- Codeforces 1120D (树形DP 或 最小生成树)
题意看这篇博客:https://blog.csdn.net/dreaming__ldx/article/details/88418543 思路看这篇:https://blog.csdn.net/cor ...
- jQuery基础,选择器
jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设计的宗旨是“write Less, ...