简体   繁体   中英

get parameter from url and after submitting form append this parameter with action

/ * current page 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>

I want to get parameters from url and when form is submitted, the url parameter will append to a new action (addaction)

PROBLEM

get "categoryId=1" and when submit button is pressed append "categoryId=1" with an action

What I understand from your code you want to resend catgoryId with product's form data and categoryId is available is in URL. I thought don't need to use window.location and use the following code for your problem solution

 </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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM