
[英]How to pass Action class variable value into another Action class in Struts 2
[英]How to pass a form variable from one action to another action class in Struts 1.2
如何将表单变量从一个动作传递到另一个动作?
这是示例:(MyContractForm在请求范围内)
MyContractForm.java
{
private Calendar creationDate = Calendar.getInstance();
}
MyContractAction@method1
{
myContractForm.setCreationDate(Calendar.getInstance());
forward to myContract.Jsp
}
MyContract.JSP
{
<script type="text/javascript">
//For a button - javascript
function getStatus()
{
document.myContractForm.dispatch.value = "method2";
document.myContractForm.submit();
}
</script>
<html:form>
<button type="button" id="btnStatus" onclick="getStatus()">Get Status</button>
</html:form>
}
MyContractAction@method2
{
// should be able to access creationDate value that was set in method1
}
我们怎样才能做到这一点?
您可以使用request
对象在struts
类和JSP之间传递值
方法一:
request.setAttribute("attr","value");
方法2:
Object obj=request.getAttribute("attr");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.