| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs JSP FAQ:
How to retrieve values from HTML form input elements in JSP pages?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
How to retrieve values from HTML form input elements in JSP?In theory, GET is for getting data from the server and POST is for sending data there. However, GET appends the form data (called a query string) to an URL, in the form of key/value pairs from the HTML form, for example, name=John. In the query string, key/value pairs are separated by & characters, spaces are converted to + characters, and special characters are converted to their hexadecimal equivalents. Because the query string is in the URL, the page can be bookmarked or sent as email with its query string. The query string is usually limited to a relatively small number of characters. The POST method, however, passes data of unlimited length as an HTTP request body to the server. The user working in the client Web browser cannot see the data that is being sent, so POST requests are ideal for sending confidential data (such as a credit card number) or large amounts of data to the server.
The
The result of Example HTML Form:
<form name="myForm" action="/result.jsp" method="post" >
<input type="checkbox" name="inputCheckbox" >
<input type="radio" name="inputRadio" value="0" >
<input type="radio" name="inputRadio" value="1" >
<input type="text" name="inputText" >
<input type="submit" >
</form>
Example JSP page (This will only display the values recieved from the submitted form):
<%= request.getParameter("inputCheckbox") %>
<%= request.getParameter("inputRadio") %>
<%= request.getParameter("inputText") %>
|