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 ...
随机推荐
- win10下默认使用福昕打开PDF
win10为了推他的edge浏览器, 将默认的pdf打开设置为了edge浏览器, 非常令人反感, 做浏览器就好好做浏览器, 为什么要默认打开pdf? 而且修改默认为福昕后, 下次打开pdf文件, 他又 ...
- 2014.8.25 CAD系统事件触发流程
各进近.离场.进场Arinc424数据录入界面在CADDataManager/UC/UCIAP(UCSID)下 UCAirport是一抽象用户控件类,在FormADHP初始化时实例化成airport控 ...
- 「小程序JAVA实战」小程序视图之细说数据绑定(13)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-13/ 在前面的小节里面其实对数据绑定都有所了解了,在这次给老铁在好好说下数据绑定,看下它的方方面面 ...
- Shell脚本 判断
#Linux系统Shell脚本判断变量文件目录:权限.是否存在.空值.相等 1.字符串判断 str1 = str2 当两个串有相同内容.长度时为真str1 != str2 当串str1和str2不等时 ...
- 通过window.crypto.getRandomValues获得一个大于零的随机数
window.crypto.getRandomValues(new Uint32Array(1))[0]; 浏览器支持情况如下: IE: no IE Mobile: no Firefox24+ Fir ...
- eth0 no such device(reload)
转载自:http://blog.chinaunix.net/uid-25554408-id-292638.html 今天我在vmware里安装了虚拟机,安装虚拟机就想安装vmware tools(这个 ...
- 移植RT2870无线网卡驱动到s3c2416
公司项目要用到usb无线网卡,芯片是ralink的RT2870.以下是将其驱动移植到s3c2416的步骤. 1.下载驱动源码,雷凌官网的下载地址是: http://www.ralinktech.com ...
- IAR FOR ARM 各版…
用过Keil和IAR,个人感觉是IAR还是很不错的.下载地址是: http://files.iar.com/ftp/pub/box/CD-EWARM-6301-3142.zip V6.30.1(该地址 ...
- pom.xml配置指定仓库
<repositories> <repository> <id>central</id><--中央仓库--> <url>http ...
- JS 页面刷新或重载
一.先来看一个简单的例子:下面以三个页面分别命名为frame.html.top.html.bottom.html为例来具体说明如何做.frame.html 由上(top.html)下(bottom.h ...