如何将表单变量从一个动作传递到另一个动作?
这是示例:(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之间传递值
方法1:
request.setAttribute("attr","value");
方法2:
Object obj=request.getAttribute("attr");