【重温】_Struts2重温笔记,要点概述_【一】

1.Myeclipse修改jsp,xml等文件默认编码格式

以jsp为例:

Widows/Preferences/MyEclipse/Files and Editors/jsp
Encoding:选择Chinese,National Standard

2.自定义action

action可以是一个普通java类,里面有public String execute方法即可,或者实现Action接口,或者是继承ActionSupport

常用的是:继承ActionSupport,因为ActionSpport有封装好的struts2方法。

3.动态方法调用DMI(dynamic method invoke)

Action执行的时候并不一定要执行execute方法
可以在配置文件中配置Action的时候用method=来指定执行哪个方法
也可以在url地址中动态指定(动态方法调用DMI)(推荐)

<a href="<%=context %>/user/userAdd">添加用户</a>
<a href="<%=context %>/user/user!add">添加用户</a>

前者会产生太多的action,所以不推荐使用

4.通配符 *{1}{2}

如:<action name="*_*" class="com.....{1}Action" method="{2}">
            <result>/{1}_{2}_success.jsp</result>
        </action>

5.解决中文乱码

struts.xml 添加<constant name="struts.i18n.encoding" value="GBK" />

6.包含文件配置

在struts.xml里添加: <include file="struts2配置文件.xml" />

7.Result类型

dispatcher,redirect,chain,redirectAction,freemarker,httpheader,stream,velocity,xslt,plaintext,tiles

常用的是dispatcher(默认),redirect,chain,redirectAction

dispatcher:服务器端跳转,只能跳转到页面(jsp,html等)

redirect:客户端跳转,只能跳转到页面

chain:服务器端跳转,forward,跳转到action

redirectAction:客户端跳转,跳转到action

8.全局结果集

global-results

一般package包继承struts-default,同时也可以继承别的package包,

如:<package name="user" namespace="/user" extends="struts-default">

        <package name="XX" namespace="/XX" extends="user">

9.<s:debug></s:debug>取值

取值栈(Value Stack Contents):<s:property value="属性名"/>

取actioncontext(Stack Context): #XX

---These items are available using the #key notation

<s:property value="#parameters.name"/>

#attr  #request ...

附:在配置文件里,取值栈的值:${}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值