简体   繁体   中英

Passing not form data from jsp page to a servlet

Does there exist a way to pass data that is not inside a form, but printed elsewhere on the jsp page, to a servlet.

If the data is inside a form it is easy, but when the data is for example inside a div, how can one send those values with the form to the servlet?

尝试这个:

<form action="{your action}?name=Jigar Joshi"> ... </form>

You can always include hidden input fields inside the form you want to submit.

<input type="hidden" name="number" value="${number}">
<input type="hidden" name="id" value="${id}">
<input type="hidden" name="department" value="${department}">

This is how I do it. When the page is loaded in, the values will be placed on your page (outside the form) and in the hidden input fields inside the form.

You can then get those hidden values on your servlet by doing this:

String number = request.getParameter("number");

Hope this helps for you.

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