struts2学习笔记(持续更新)

struts2学习笔记(持续更新)

  1. struts.xml配置:要打开开发模式,即把value的值设为true,否则改动需要重启

  2. namespace决定action的访问路径,默认为"",可以接收所有路径的action。namespace可以写为"/","/xxx","/xxx/yyy"对应的action路径为/index.action,/xxx/index.action,/xxx/yyy/index.action
    -namespace决定action的访问路径,默认为"",可以接收所有路径的action。namespace可以写为"/","/xxx","/xxx/yyy"对应的action路径为/index.action,/xxx/index.action,/xxx/yyy/index.action

  3. 路径问题,若action 跳转到某个jsp页面,这个jsp页面又有跳转链接,不能设置相对路径,要设置绝对路径,用basePath来设置,<%String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>,①<a href=basePath+"index.jsp"></a><base href="<%=basePath%>"> <a href="index.jsp></a>

  4. 开发模式不能动态修改result中的内容,若修改result中的需要重启服务器。
    `

  5. struts2.5默认是严格调用,要想使用DMI,struts.xml要做一下设置
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
    strict-method-invocation="false"struts2.5默认是true,要设置为false

  6. Action总结在这里插入图片描述

  7. chain跳转问题:首先,我先来查看一下,下载struts2里面的docs文件,从里面的index文件中可以查看相关的内容

Parameters*

actionName (default) - the name of the action that will be chained to.
namespace - used to determine which namespace the Action is in that we’re chaining. If namespace is null, this defaults to the current namespace.
method - used to specify another method on target action to be invoked. If null, this defaults to execute method.
skipActions - (optional) the list of comma separated action names for the actions that could be chained to.
*

Examples*

<package name="public" extends="struts-default">
    <!-- Chain creatAccount to login, using the default parameter -->
    <action name="createAccount" class="...">
        <result type="chain">login</result>
    </action>
 
    <action name="login" class="...">
        <!-- Chain to another namespace -->
        <result type="chain">
            <param name="actionName">dashboard</param>
            <param name="namespace">/secure</param>
        </result>
    </action>
</package>
 
<package name="secure" extends="struts-default" namespace="/secure">
    <action name="dashboard" class="...">
        <result>dashboard.jsp</result>
    </action>
</package>

从给出的example可以看出,总共有三种跳转方法,第一种是跳到同一个package中,第二个是跳到不同package中,这里着重讲解第二种方法,在result中加两个param参数,name里面的内容是写死的,不要去修改它,第一个参数对应着你要跳到的action的名称,第二个是你要跳到的package里的namespace

  1. Result总结在这里插入图片描述
  2. 用Domain Model的时候,pojo要么不写构造方法(编译器会自动帮你生成无参的构造方法),如果写了构造方法,就要把无参的默认方法写上去,要不然会报错
  3. 通配符问题,当我设置为"_“的时候,可能会有匹配错误,即不论是不是应该匹配到这个通配符的action,都匹配进去了,造成错误,目前的解决方法,只能把中间的"_"设复杂点,测试”__",即两个_,又可以正常运行了
  4. ajax中的dataType是回传数据类型
  5. 使用struts2.5一定要记得把strict-method-invocation设为false
  6. jquery的对标签做操作,定义函数的时候,需取class来操作,即 ( " . c l a s s " ) , 不 可 以 用 i d 操 作 , 即 (".class"),不可以用id操作,即 (".class")id("#id")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值