简体   繁体   English

从url获取参数,并在提交表单后将此参数附加到动作中

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

/ * current page url* / / *当前页面的网址* /
/ AddProduct.jsp?categoryId=1 / / 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) 我想从url获取参数,并在提交表单时将url参数附加到新操作(addaction)

PROBLEM 问题

get "categoryId=1" and when submit button is pressed append "categoryId=1" with an action 获取“ categoryId = 1”,并在按下“提交”按钮时将“ categoryId = 1”附加到动作

What I understand from your code you want to resend catgoryId with product's form data and categoryId is available is in URL. 我从您的代码中了解到,您想使用产品的表单数据重新发送catgoryId,并且categoryId可用在URL中。 I thought don't need to use window.location and use the following code for your problem solution 我认为不需要使用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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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