这里是传值 <a href="useradd.jsp?personId=${p.id}">添加账号</a> 在另外一个添加页面需要获得personId,并调用useradd action。<% int id = Integer.parseInt(request.getParameter("personId")); %>其中id已经正确得到值。关键是下一步 <s:form action="useradd">
<s:hidden name="personId" value="??????"></s:hidden>
<s:textfield name="user.username"></s:textfield>
<s:submit>添加</s:submit>
</s:form> 我需要将得到的id值赋值给name 为personId的参数,以便在action里面自动获取。求救啊,在线等 先谢过大虾了
<s:hidden name="personId" value="<%=id%>"></s:hidden> 这张方法是不行的
<s:hidden name="personId" value="??????"></s:hidden>
<s:textfield name="user.username"></s:textfield>
<s:submit>添加</s:submit>
</s:form> 我需要将得到的id值赋值给name 为personId的参数,以便在action里面自动获取。求救啊,在线等 先谢过大虾了
<s:hidden name="personId" value="<%=id%>"></s:hidden> 这张方法是不行的
还报错
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: /useradd.jsp(16,2) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1172)
把这个换成html 的hidden,再用<%=id%>应该没问题
这样<s:hidden name="personId" value="<s:property value='#request.personId'/>"/>,至于这么怎么封装变量,自己先去看struts2的标签库去!
<s:hidden name="personId" value="%{#request.personId}"></s:hidden>
或者也可以换成普通HTML标签:
<input type="hidden" value="<%=id %>">