YouTip LogoYouTip

Jsp Form Processing

Tutorial -- Learning is not just about technology, but also about dreams! Home HTML JAVASCRIPT CSS VUE REACT PYTHON3 JAVA C C++ C# AI GO SQL LINUX VS CODE BOOTSTRAP GIT Local Bookmarks JSP Tutorial JSP Tutorial JSP Introduction JSP Development Environment Setup Eclipse JSP/Servlet JSP Structure JSP Lifecycle JSP Syntax JSP Directives JSP Action Elements JSP Implicit Objects JSP Client Request JSP Server Response JSP HTTP Status Codes JSP Form Processing JSP Filters JSP Cookie Handling JSP Session JSP File Upload JSP Date Processing JSP Page Redirection JSP Hit Counter JSP Auto Refresh JSP Send Email JSP Advanced Tutorial JSP Standard Tag Library (JSTL) JSP Database Connection JSP XML Data Processing JSP JavaBean JSP Custom Tags JSP Expression Language JSP Exception Handling JSP Debugging JSP Internationalization JSP HTTP Status Codes JSP Filters Deep Dive Programming Languages Software Development Tools Web Design & Development Programming Scripting Languages Scripts Computer Science Web Service Web Services JSP Form Processing When browsing web pages, we often need to submit information to the server and let the backend program process it. Browsers use GET and POST methods to submit data to the server. GET Method The GET method appends the encoded information of the request to the end of the URL. The URL and the encoded information are separated by a "?" character. As shown below: GET is the default method browsers use to pass parameters. It is recommended not to use the GET method for sensitive information, such as passwords. When using GET, the size of the transmitted data is limited (note that it's not the number of parameters that is limited), with a maximum of 1024 bytes. POST Method We can transmit some sensitive information, such as passwords, using the POST method. POST data submission is implicit. POST data submission is not visible, whereas GET passes data through the URL (you can check your browser's address bar). JSP uses getParameter() to obtain the passed parameters, and the getInputStream() method is used to handle binary data stream requests from the client. JSP Reading Form Data getParameter(): Use the request.getParameter() method to get the value of a form parameter. getParameterValues(): To get data like checkboxes (same name, but multiple values). Accepts an array variable, such as for checkbox types. getParameterNames(): This method can get the names of all variables. It returns an Enumeration. getInputStream(): Call this method to read binary data streams from the client. GET Method Example Using URL Here is a simple URL, using the GET method to pass parameters in the URL: testjsp is the project address. Below is the JSP code in the main.jsp file for processing form data submitted by the client. We use the getParameter() method to retrieve the submitted data:

Reading Data Using GET Method

  • Site Name:

  • URL:

Next, we access via a browser, and the output result is as follows: GET Method Example Using Form Here is a simple HTML form that submits client data to the main.jsp file using the GET method: Site Name:
URL: Save the above HTML code to a file named test.htm. Place this file in the WebContent directory of the current JSP project (in the same directory as main.jsp). By accessing http://localhost:8080/testjsp/test.html to submit form data to the main.jsp file, the demonstration Gif is shown below: Fill in the information in the "Site Name" and "URL" form fields and click the "Submit" button, and it will output the result. POST Method Example Using Form Next, let's use the POST method to pass form data. Modify the code in main.jsp and test.htm files as follows: main.jsp file code:

Reading Data Using POST Method

  • Site Name:

  • URL:

In the code, we use new String((request.getParameter("name")).getBytes("ISO-8859-1"),"UTF-8") to convert the encoding and prevent Chinese character garbling. Below is the modified code for test.htm: Site Name:
URL: By accessing http://localhost:8080/testjsp/test.html to submit form data to the main.jsp file, the demonstration Gif is shown below: Passing Checkbox Data to JSP Program A checkbox can pass one or even multiple pieces of data. Here is a simple HTML code, save it in a file named test.htm: Google Tutorial Taobao The above code is displayed in the browser as follows: Below is the code for the main.jsp file, used to process checkbox data:

Reading Data from Checkboxes

  • Is Google selected:

  • Is Tutorial selected:

  • Is Taobao selected:

By accessing http://localhost:8080/testjsp/test.html to submit form data to the main.jsp file, the demonstration Gif is shown below: Reading All Form Parameters Next, we will use the getParameterNames() method of HttpServletRequest to read all form parameters. This method can get the names of all variables and returns an Enumeration. Once we have an Enumeration, we can call the hasMoreElements() method to determine if there are more elements, and use the nextElement() method to get the name of each parameter.

Reading All Form Parameters

<% Enumeration paramNames = request.getParameterNames(); while(paramNames.hasMoreElements()) { String paramName = (String)paramNames.nextElement(); out.print("n"); String paramValue = request.getParameter(paramName); out.println("n"); } %>
Parameter NameParameter Value
" + paramName + " " + paramValue + "
Below is the content of the test.htm file: Google Tutorial Taobao Now we access the test.htm file via a browser to submit data, and the output result is as follows: By accessing http://localhost:8080/testjsp/test.html to submit form data to the main.jsp file, the demonstration Gif is shown below: You can try using the above JSP code to read other objects, such as text boxes, radio buttons, dropdown menus, and other forms of data. JSP HTTP Status Codes JSP Filters ByteArk Coding Plan Supports mainstream large models like Doubao, GLM, DeepSeek, Kimi, MiniMax, officially supplied, stable and reliable. Configuration Guide ¥9.9 / Month Subscribe Now iFlytek Spark Coding Plan Includes free model call quotas, DeepSeek, GLM, Kimi, MiniMax, a one-stop experience and deployment platform. Configuration Guide ¥3.9 / Month Subscribe Now Click here to share notes Category Navigation Python / Data Science AI / Intelligent Development Front-end Development Back-end Development Database Mobile Development DevOps / Engineering Programming Languages Computer Fundamentals XML / Web Service .NET Website Building Advertisement JSP Tutorial JSP Tutorial JSP Introduction JSP Development Environment Setup Eclipse JSP/Servlet JSP Structure JSP Lifecycle JSP Syntax JSP Directives JSP Action Elements JSP Implicit Objects JSP Client Request JSP Server Response JSP HTTP Status Codes JSP Form Processing JSP Filters JSP Cookie Handling JSP Session JSP File Upload JSP Date Processing JSP Page Redirection JSP Hit Counter JSP Auto Refresh JSP Send Email JSP Advanced Tutorial JSP Standard Tag Library (JSTL) JSP Database Connection JSP XML Data Processing JSP JavaBean JSP Custom Tags JSP Expression Language JSP Exception Handling JSP Debugging JSP Internationalization Online Examples ·HTML Examples ·CSS Examples ·JavaScript Examples ·Ajax Examples ·jQuery Examples ·XML Examples ·Java Examples Character Sets & Tools · HTML Character Set Settings · HTML ASCII Character Set · JS Obfuscation/Encryption · PNG/JPEG Image Compression · HTML Color Picker · JSON Formatter Tool · Random Number Generator Latest Updates · Large Model Multimodal (M... · Codex Advanced Configuration · AI Agent Terminology · ZCode Getting Started Tutorial · Loop Engineerin... · Claude Code Usage... · Claude Code Usage... Site Information · Feedback · Disclaimer · About Us · Article Archive Follow WeChat My Favorites Mark Article Browsing History Clear All No records yet
← Jsp Writing FiltersJsp Http Status Codes →