Javascript 从url获取参数,并在提交表单后使用操作附加此参数

Javascript 从url获取参数,并在提交表单后使用操作附加此参数,javascript,struts2,Javascript,Struts2,/*当前页面url*/ /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?"+hash

/*当前页面url*/
/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>

函数abc(){
var hashes=window.location.href.slice(window.location.href.indexOf('?')+1).split('&');
window.location=“addproduct.action?”+散列;
返回false;
}
我想从url获取参数,当表单提交时,url参数将附加到一个新操作(addaction)中

问题
获取“categoryId=1”,当按下提交按钮时,用一个动作附加“categoryId=1”

我从您的代码中了解到,您想要用产品的表单数据重新发送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>