项目____SSH框架jsp-action映射、传参、重定向再理解
来源:互联网 发布:电脑没网络怎么回事 编辑:程序博客网 时间:2024/05/20 16:34
实现的功能:翻页查询附带查询条件,更新后留在所更新内容的位置
JSP1:
<span style="white-space:pre"></span><form id="formPage" method="post" action="${ctx}/basicInfor/ddsManage/dds!ogc.action"> <span style="white-space:pre"></span><!-- 这里的hidden型的数据随表提交 用于翻页查询时保留查询数据 调用的action除非要在action内修改传入的数据 否则不需要在外部声<span style="white-space:pre"></span>明private型的同名变量来获取此传入值,而在mybatis的xml中写sql语句时 可以直接使用${starttime}来获取范围内key为starttime的开<span style="white-space:pre"></span>始时间 --><input type="hidden" id="starttime" name="starttime" value="${data.starttime }" /><table class="table" style="border-bottom: 1px solid #ddd; font-size: 12px;"><!-- table-striped --><thead></thead><span style="white-space:pre"></span><tobody></tbody></table><%@ include file="/common/bspage.jsp"%></form>#若不设置method:由于默认方法是get,get是通过url提交信息,导致提交的中文字段必须编码,在接收端必须解码,否则会因为出现的编码错误导致数据错误。
#若不设置action:当操作更新打分项时,由于返回的url路径不是查询.action而是更新.action,导致翻页时请求的action也是更新.action,可能因为没有相应的参数导致空指针等内部错误。
JSP2:
<span style="white-space:pre"></span><s:form id="uploadForm" method="post" theme="simple" enctype="multipart/form-data"><input type="hidden" id="starttime" name="starttime" value="${data.starttime }" /><input type="hidden" id="selPageRow" name="selPageRow" value="${data.selPageRow }" /> <table align="center" width="50%" border="1"> <tr> <td>图片描述</td> <td > <s:file id="imgfile" name="imgfile"></s:file> </td> </tr> <tr> <td>区域描述</td> <td><s:textfield id="key_description" name="key_description"></s:textfield></td> </tr> <tr> <td>评分</td> <td><s:select id="key_score" name="key_score" list="#{'1':'1','2':'2','3':'3','4':'4'}" <span style="white-space:pre"></span>label="评分" headerKey="3" headerValue="3"></s:select></td> </tr> <tr> <span style="white-space:pre"></span><td><s:reset value=" reset "></s:reset></td> <span style="white-space:pre"></span></tr> </table><span style="white-space:pre"></span></s:form>通过以下操作,
<input type="hidden" id="starttime" name="starttime" value="${data.starttime }" /><input type="hidden" id="selPageRow" name="selPageRow" value="${data.selPageRow }" />
将页码信息,搜索信息等传入action中。
action:
声明——提交到action的需要被操作的数据的同名变量。
<span style="white-space:pre"></span>private String starttime;<span style="white-space:pre"></span>private String endtime;<span style="white-space:pre"></span>private String product_line2;<span style="white-space:pre"></span>private String banci2;<span style="white-space:pre"></span>private String banzu2;</span><span style="white-space:pre"></span>private int selShowpageNO;<span style="white-space:pre"></span>private int selPageRow;<span style="white-space:pre"></span>public void setSelShowpageNO(int selShowpageNO) {<span style="white-space:pre"></span>this.selShowpageNO = selShowpageNO;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>public int getSelShowpageNO() {<span style="white-space:pre"></span>return selShowpageNO;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>public void setSelPageRow(int selPageRow) {<span style="white-space:pre"></span>this.selPageRow = selPageRow;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>public int getSelPageRow() {<span style="white-space:pre"></span>return selPageRow;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>..省略了..
通过以上,可以在action中操作这些变量,将其赋值到data中
<span style="white-space:pre"></span>data.set("starttime", starttime);<span style="white-space:pre"></span>data.set("endtime", endtime);<span style="white-space:pre"></span>data.set("product_line2", product_line2);<span style="white-space:pre"></span>data.set("banci2", banci2);data.set("banzu2", banzu2);data.set("selShowpageNO", selShowpageNO);data.set("selPageRow", selPageRow);
返回特定字符串
return "reload";
根据返回的字符串决定重定向位置
@Results({ @org.apache.struts2.convention.annotation.Result(name = "reload", location = "dds!ogc.action?starttime=${data.starttime}&endtime=${data.endtime}" +"&product_line2=${data.product_line2}&banci2=${data.banci2}&banzu2=${data.banzu2}", type = "redirectParams") })#注意,这里使用的是data中的数据,data.starttime所以需要声明同名变量,setget,对data赋值。如果只是使用提交上来的${starttime}关键字,估计可以直接使用
#注意,前面设置了selxx的相关内容,这里action地址中不需要具体设置,会自动添加进去。应该是page相关项自己的方法?
0 0
- 项目____SSH框架jsp-action映射、传参、重定向再理解
- index.jsp重定向到action
- jsp之重定向和转发理解
- struts2 action重定向
- action重定向
- struts2 action重定向action
- 深入理解Servlet/JSP之“转发和重定向”
- 深入理解Servlet/JSP之“转发和重定向
- jsp重定向与转发的理解和区别
- jsp重定向
- JSP重定向
- JSP的重定向
- jsp页面重定向
- JSP 页面重定向
- JSP重定向技巧
- JSP的重定向
- Jsp重定向
- jsp重定向
- 实现iOS全局禁止横屏,但kxmovie全屏横屏播放视频
- 进度条 UIProgressView
- OCP-V13-025
- OCP-V13-026
- OCP-V13-027
- 项目____SSH框架jsp-action映射、传参、重定向再理解
- 猴子摘桃问题原创代码递归+循环两种方法实现
- 如何解决ubuntu 12.04重启后出现waiting for network configuration和网络标志消失问题
- OCP-V13-028
- 94 数据结构和方向感言
- 多线程并发上传
- OCP-V13-029
- 数学之神
- DirectX11 计时和动画