/ *当前页面网址* /
/AddProduct.jsp?categoryId=1/
<script type="text/javascript">
function abc(){
var hashes = window.location.href.slice(window.location.href.indexOf('?')+1).split('&');
window.location="addproduct.action?"+hashes;
return false;
}
</script>
</head>
<body>
<s:form method="post" enctype="multipart/form-data">
<s:textfield label="Name" name="productBean.name" id="productBean.name"/>
<s:textfield label="Price" name="productBean.price" id="productBean.prsice"/>
<s:textfield label="Description" name="productBean.description" id="productBean.description"/>
<s:label name="upload" value="Image"></s:label>
<s:file name="upload"> </s:file>
<s:submit onclick='abc()' value="Add Product" ></s:submit>
</s:form>
我想从url获取参数,并且在提交表单时,url参数将附加到新操作(addaction)
获取“categoryId = 1”并按下提交按钮时附加“categoryId = 1”并带有动作
答案 0 :(得分:0)
我从您的代码中了解到您希望使用产品的表单数据重新发送catgoryId并且categoryId可用于URL。我认为不需要使用window.location并使用以下代码来解决问题
</head>
<body>
<s:form method="post" enctype="multipart/form-data" action="addproduct.action">
<s:textfield label="Name" name="productBean.name" id="productBean.name"/>
<s:textfield label="Price" name="productBean.price" id="productBean.prsice"/>
<s:textfield label="Description" name="productBean.description" id="productBean.description"/>
<s:label name="upload" value="Image"></s:label>
<s:file name="upload"> </s:file>
<input type="hidden" value="${param.categoryId}">
<s:submit value="Add Product" ></s:submit>
</s:form>