strtus2基本学习记录

strtus2的NameSpace讲解,Path路径讲解
action访问的几种机制
NameSpace命名空间默认问""  可以设置为"/","/index/","/index/hello" antion对应的访问为"/*。action","/index/*。action","/index/hello/*.action"
默认时自动查找*action的访问
路径问题说明 :默认返回的是action的路径不是jsp的路径,最好都使用绝对路径
strtus2每次访问action都会生成一个新的对象,strtus1只有一个
action的访问
action的访问默认访问action的execute方法,可以在struts的配置文件中指定method,也可以使用通配符对应通配符值对应请求action的值
action参数传递,数据验证,中文乱码
*.action?变量名=传递的值。接收的action中必须由变量的get,set方法
*.action?对象名.对象属性=传递的值。接收的action中必须由对象的get,set方法
<constant name="struts.i18n.encoding" value="GBK" /><!--配置action接收中文不乱码-->必须post提交
获取request、session、appliaction的web元素交互

strtus2中action的result的几种方式,include配置其他strtus2文件,设置命名空间默认的action访问
<include file="strtus.xml">加载其他的配置文件
<defalut-action-ref  name="指定action的name" />设置strtus命名空间默认访问的action
rsult设置type默认为dispatcher(收发)只能跳转到jsp或者html类似于请求转发,redirect()更改只能跳转到jsp或者html类似于重定向
  chin跳转到action的名字类似于请求转发,redirectAction跳转到action类似于重定向
全局result定义
<global-result><result name="返回的字符串">*.jip</result></global-result>
如另一个packg配置中需要用到,用extends继承存在全局的packge包名。动态结果集返回,在action定义一个string变量'*.jsp',在strtus中用${string变量名}
ognl简单的说就是获取值栈中的值,配合debug标签查看
访问action中的属性<s:property value="userName"/>
<br/>
访问action中的属性的方法<s:property value="userName.length()"/>
</br>
访问action中对象的属性对象必须有不带参数的构造方法或者domainmode传值进去也可以自己new : <s:property value="user.uname"/>|<s:property value="user.dogMake.dogName"/>
</br>
访问action中对象的方法 : <s:property value="user.addSex()"/>
<br/>
获取list的值<s:property value="users[0].uname"/>
<br/>
获取map的所有keys<s:property value="map.keys"/>
<br/>
获取map所有的值<s:property value="map.values"/>
获取map的某个键的值<s:property value="map.dog1.dogName"/>
strtus2 标签基本标签
s:property默认访问ognl中的内容<s:property value="userName"/><br/>
s:property默认访问ognl中的内容,加单引号定义字符串变量<s:property value="'userName'"/><br/>
s:property默认访问ognl中的内容,default设置默认值<s:property value="userN" default="xiao"/><br/>
s:set默认设置一个属性放在request和application中<s:set var="uname" value="userName"/><br/>
s:set scope设置属性的范围<s:set var="usex" value="'男'" scope="session"/><br/>
取 scope设置属性的范围<s:property value="#session.usex"/><br/>
取request中的值<s:property value="#request.uname"/><br/>
取application中的值<s:property value="#uname"/><br/>
取request中的值<%=request.getAttribute("uname") %><br/>
s:ben创建对象s:param设置bean的属性内容<s:bean name="com.xiao.entity.Dog" var="dog1">
<s:param name="dogName" value="'hahha'"></s:param>
</s:bean><br/>
if else标签<s:if test="1<2">正确</s:if>
<s:else>错误</s:else>
s:iterator迭代标签<s:iterator  value="{1,2,3}">
<s:property/>
</s:iterator>
<br/>
iterator测试二
<s:iterator value="{1,2,3,4,5}" begin="2" end="4" >
   <!-- current iteration value (2,3,4) -->
   <s:property value="top" />
</s:iterator>
<br/>
<s:iterator value="#{1:'a',2:'b',3:'c'}" var="hehe">
   <!-- current iteration value (2,3,4) -->
   <s:property value="#hehe.value" />
    <s:property value="#hehe.key" />
</s:iterator>
设置strtus2配置热部署,全局异常访问,注意action中的异常都要抛出
<constant name="strtus.devMode" value="true"/>设置strtus2配置热部署debug模式,
<golbal-exception-mappings result="变量名" exception="java.lang,exception">设置全局错误返回。<global-result><result name="返回的字符串">*.jip</result></global-result>配合golbal-result标签使用,新建包让包继承定义异常的包
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值