struts2的视图类型+中文编码+在struts.xml配置中如何传递action中的属性值

struts2是通过filter来初始化配置的,struts1 是通过servlet 加载配置的

action名称的搜索路径,按包的顺序从里往外搜

1>如果没有为action指定class,默认是ActionSupport。
2>如果没有为action指定method , 默认执行action中的execute()方法 。
3>如果没有为result指定name属性 , 默认为success 。

[b][color=darkred]视图类型[/color][/b]

1. 重定向的类型:dispatch(默认值),redirect(客户端跳转),redirectAction,plainText

2 . 在action中的参数可以在result中间配置
 <action name="list" class="cn.itcast.action.HelloWorldAction" method="execute">
<result name="success" type="redirect">/employeeAdd.jsp?username=${username}</result>
</action>
(在action必须有getUsername()方法)
与struts 1 相比,灵活性强,struts1 是在action中把参数设置在request中 ,然后在jsp页面上从request中获得


3 . redirectAction:从一个action跳转到另一个action
访问不在同一包中的action
<action name="redirectAction">
<result type="redirectAction">
<param name="actionName">xxx</param>
<param name="namespace">/control/department/xdsfdsfds/435435</param>
</result>
</action>
4 . plainText:显示原始文件
 <action name="plainText">
<result type="plainText">
<param name="location">/index.jsp</param>
<param name="charSet">UTF-8</param><!-- 指定读取文件的编码 -->
</result>
</action>

5 . 定义全局视图
我们知道在包中可以定义<global-results> ,但只有包中的action共享这个视图,其他包无法访问
如何定义全局视图?
定义一个包
 <package name="base" extends="struts-default">
<global-results>
<result name="message">/WEB-INF/page/message.jsp</result>
</global-results>
</package>
然后让其他的包都继承自这个包
<package name="itcast" namespace="/control/employee" extends="base">
</package>
这样就所有的包都能共享这个视图

6 . 在action中传递中文要转码,在jsp中要解码(只针对客户端的get方式跳转)
action中转码:
this.username = URLEncoder.encode("传智播客", "UTF-8");
jsp中解码:
 <%= URLDecoder.decode(new String(request.getParameter("username").getBytes("ISO8859-1"),"UTF-8"),"UTF-8") %>

7 . 在result中如何传递多个参数
<result name="success" type="redirect">/employeeAdd.jsp?username=${username}&id=${id}</result>
&要转码(&)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值