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 ...
随机推荐
- html5测试总结
1.因为html5不兼容IE78,所以在PC上使用并非十分光.pc上IE还是占主流 2.html5主要用在移动终端 3.html5短期内因为自身的缺陷,用户体验无法达到原生app的体验.如:html5 ...
- 浅层神经网络 反向传播推导:MSE softmax
基础:逻辑回归 Logistic 回归模型的参数估计为什么不能采用最小二乘法? logistic回归模型的参数估计问题不能“方便地”定义“误差”或者“残差”. 对单个样本: 第i层的权重W[i]维度的 ...
- ssh secure shell 乱码问题
1. 执行命令 locale 查看,出现如下: [root@catxjd ~]# locale LANG=zh_CN.GB2312 LC_CTYPE="zh_CN.GB2312" ...
- zookpeer的安装与配置
zookpeer集群搭建: 集群搭建过程简介: 这里准3台服务器做zk(zookpeer下面简称zk)集群搭建: zk集群由一个leader和两个follower组成,对外端口默认为2181端口,关于 ...
- python动态爬取网页
简介 有时候,我们天真无邪的使用urllib库或Scrapy下载HTML网页时会发现,我们要提取的网页元素并不在我们下载到的HTML之中,尽管它们在浏览器里看起来唾手可得. 这说明我们想要的元素是在我 ...
- 非常详细的ok6410的linux系统移植…
目录 Linux 3.3.5系统移植 2 LED驱动移植 8 按键驱动移植 9 LCD驱动移植 11 DM9000网卡驱动移植 14 搭建NFS网络文件系统 25 移植触摸屏驱动 38 移植Qt4.8 ...
- sqlplus客户端 navicat 使用sqlplus OCI
链接:http://pan.baidu.com/s/1i5otsUT 密码:cbux 解压后放到某个目录下 这是我的 sqlplus客户端出现乱码 - 一支小白 - 博客园 http://www.c ...
- 固本培元之三:Convert、运算符、流程控制语句、ref/out/in三种参数类型
一.Convert类常用的类型转换方法Convert.ToInt32() 转换为整型(int)Convert.ToChar() 转换为字符型(char)Convert.ToString() 转换为字符 ...
- VBox 安装 Ubuntu Server 的那些坑,键盘乱码、网卡互连、共享目录等
1.更新,相信大家都是有强迫症的 sudo apt-get update sudo apt-get upgrade 出现错误:Could not open lock file /var/lib/dpk ...
- 733. Flood Fill 简单型染色问题
[抄题]: An image is represented by a 2-D array of integers, each integer representing the pixel value ...