在使用struts2开发web程序时,有些时候遇到这种情况,在页面的struts2表单提交的时候需要传递参数,而且这个参数是从其他页面或action中传递过来的参数,这个时候需要注意:
如果写成:
<s:form action="moveStuff?sid=<%=sid%>" method="post">
这样是不能传递该参数的,因为通过<%=sid%>获取不到对应的sid值,要改成一下表达式:
<s:form action="moveStuff?sid=%{#parameters.sid}" method="post" theme="simple" target="viewFrame">
库号
<s:select name="wareHouse.wno" list="{'A库','B库'}" headerKey="-1"
headerValue="请选择" />
区号
<s:select name="wareHouse.wsectno" list="{'1区','2区','3区'}"
headerKey="-1" headerValue="请选择" />
层号
<s:select name="wareHouse.wlayerno" list="{'1层','2层'}" headerKey="-1"
headerValue="请选择" />
位号
<s:textfield size="4" name="firstBitNo"></s:textfield>到<s:textfield
size="4" name="lastBitNo"></s:textfield>
<s:submit value="查看库位情况" method="viewUseredOrNot"></s:submit>
<s:submit value="原料移库" method="moveStuff"></s:submit>
</s:form>
其中:#parameters.sid是Struts2中的命名对象parameters用户获取请求参数,是一个Map类型的对象,以请求参数的名字作为键(key),以请求参数的值作为值(value)。
如果写成:
<s:form action="moveStuff?sid=<%=sid%>" method="post">
这样是不能传递该参数的,因为通过<%=sid%>获取不到对应的sid值,要改成一下表达式:
<s:form action="moveStuff?sid=%{#parameters.sid}" method="post" theme="simple" target="viewFrame">
库号
<s:select name="wareHouse.wno" list="{'A库','B库'}" headerKey="-1"
headerValue="请选择" />
区号
<s:select name="wareHouse.wsectno" list="{'1区','2区','3区'}"
headerKey="-1" headerValue="请选择" />
层号
<s:select name="wareHouse.wlayerno" list="{'1层','2层'}" headerKey="-1"
headerValue="请选择" />
位号
<s:textfield size="4" name="firstBitNo"></s:textfield>到<s:textfield
size="4" name="lastBitNo"></s:textfield>
<s:submit value="查看库位情况" method="viewUseredOrNot"></s:submit>
<s:submit value="原料移库" method="moveStuff"></s:submit>
</s:form>
其中:#parameters.sid是Struts2中的命名对象parameters用户获取请求参数,是一个Map类型的对象,以请求参数的名字作为键(key),以请求参数的值作为值(value)。