简体   繁体   中英

Passing multiple values in JSP url

I am trying to pass multiple values in a JSP page url to another one. The code is:

<form name="QuantityForm" onsubmit="return quantityValidation()" action='<%="basket.jsp?addItem="+product.PID%>' method="post">
        Quantity <input type="text" name="quantity" size="5">
        <input class="button button2" type="submit" value="Add to basket" />    
</form>

How do i pass the value of quantity (the field of name="quantity" ) in the same URL? i know it's something like "Search.jsp?item=<%=search%>&item2=value2&item3=value3.." but i can't seem to structure it properly. Thanks

Do not put your ? and parameters in the action url. Put your parameters in input tags:

<form name="QuantityForm" onsubmit="return quantityValidation()" action='basket.jsp' method="post">
        <input type="hidden" name="addItem" value="%product.PID%">
        Quantity <input type="text" name="quantity" size="5">
        <input class="button button2" type="submit" value="Add to basket" />    
</form>

you're using method="post" which doesn't allow parameters to be passed into the url. change it to method="get" if you want the parameters to be passed along with the url.

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