struts2总结

来源:互联网 发布:ahocorasick python 编辑:程序博客网 时间:2024/05/17 00:59

一:struts2的jar包

二:struts2动态方法调用的3种方法

三:struts2访问servletApi的3种方法

四:其他

   1,namespace为空时。。。

   2.web项目copy后一定要改对应的web context-root


五:为什么会出现一次请求,action响应两次?如何解决?


错误方法一:action方法执行两次,js:submit方法执行一次。因为form表单中的submit会提交一次请求,js方法中的submit会再提交一次请求

<form name="editForm" method="post" enctype="multipart/form-data" onsubmit="checkFile()">  
        <input id="file" type="file" name="sendedExcel" style="width: 300px"/><br/>  
        <input type="submit" value="导入"/>  
        <s:token/>  
    </form>  


错误方法二:不会执行action方法,甚至不会执行js:submit方法

<form name="editForm" method="post" enctype="multipart/form-data">  
        <input id="file" type="file" name="unSendedExcel" style="width: 300px"/><br/>  
        <button type="button" onclick="submit()">导入</button>
        <s:token/>  
    </form>

正确方法: 

<form name="editForm" method="post" enctype="multipart/form-data">  
        <input id="file" type="file" name="unSendedExcel" style="width: 300px"/><br/>  
        <s:token/>  
        </form>  
    <button type="button" onclick="submit()">导入</button>

六:struts2中<s:if> 中==不好用,应该用!=???

七:<s:if>中判断字符串相等

正确:<s:if test='#session.user.role=="3"'>

错误:<s:if test="#session.user.role=='3'">


八:如何使用标签获取session或application中的值?

<s:if test='#session.user.role=="3"'>


九:如何给result type=“chain” 传递参数?

  <resulttype="chain">
            <paramname="actionName">order</param>
            <paramname="namespace">/b2c</param>
<paramname="status">11</param>
<paramname="...">....</param>
  </result>

十:js如何获取struts2的标签的值?

通过id,jquery获取

var status=$("#status").val(); 

<input type="hidden" id="status" name="queryOrder.status" value="<s:property value="queryOrder.status"/>" />