【问题标题】:get parameter from url and after submitting form append this parameter with action从 url 获取参数并在提交表单后将此参数附加到操作中
【发布时间】:2011-10-25 10:38:03
【问题描述】:

/* 当前页面网址*/
/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”和操作

【问题讨论】:

    标签: javascript struts2


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-03
      • 2012-01-18
      • 1970-01-01
      • 2012-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多