- Java Guides
- The Methods in Form Processing
- GET method
- POST method
- Reading Form Data using JSP
- Reading HTML Form Data with JSP
- 1. Read HTML Form Input Text field Value
- student-form.html
- Output
- student-response.jsp
- Output
- 2. Read HTML forms select box (drop-down list) value in JSP
- student-dropdown-form.html
- 3. Read HTML Form’s radio button value data
- student-form-radio.html
- Read HTML Form checkbox field value
- student-checkbox-form.html
- student-checkbox-form.jsp
- Radio Button in JSP Page Example
- Overview
- Complete Example
- Create a Project
- Create a HTML form
- Create a JSP file
- Run the file
- Related posts:
- About the author
- Bushan Sirgur
- How to use radio button in jsp page
- How to use radio button in jsp page
- How to use radio button in jsp page
- Welcome .
- Tutorials
Java Guides
This article is a series of JSP Tutorial . In this article, we will learn how to make use of HTML forms with JSP. We will build a complete Student Registration HTML Form with input button, checkbox button, radio button, and dropdown list etc. Along with this, we will also learn how to read HTML form elements data using request.getParameter() method.
The Methods in Form Processing
GET method
The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character as follows −
http://www.test.com/hello?key1=value1&key2=value2
The GET method is the default method to pass information from the browser to the web server and it produces a long string that appears in your browser’s tab. It is recommended that the GET method is better not used. if you have a password or other sensitive information to pass to the server.
POST method
This method packages the information in exactly the same way as the GET method, but instead of sending it as a text string after a ? in the URL it sends it as a separate message. This message comes to the backend program in the form of the standard input which you can parse and use for your processing.
JSP handles this type of requests using getParameter() method to read simple parameters and getInputStream() method to read binary data stream coming from the client.
Reading Form Data using JSP
getParameterValues() − Call this method if the parameter appears more than once and returns multiple values, for example — checkbox.
getParameterNames() − Call this method if you want a complete list of all parameters in the current request.
Reading HTML Form Data with JSP
- Read HTML forms input text field value in JSP
- Read HTML forms select tag (drop-down list) value in JSP
- Read HTML forms radio-button field value in JSP
- Read HTML forms checkbox tag value in JSP
1. Read HTML Form Input Text field Value
In this example, we will build an HTML form to read student information. Let’s first create a simple HTML form with input field elements. Later we will read HTML form data using JSP.
student-form.html
html> head> title>Student Registration Formtitle> head> body> form action="student-response.jsp" method="post"> First name: input type="text" name="firstName" /> br/>br/> Last name: input type="text" name="lastName" /> br/>br/> input type="submit" value="Submit" /> form> body> html>
Output
Now, we have created a simple Student registration page, in order to read from data we will create a student-response.jsp page as explained below.
student-response.jsp
- We use request.getParameter() method to get the value of a form parameter.
- We can also use $ expression language to read the input value.
- We are using an expression tag to display a result.
html> head>title>Student Confirmation Titletitle>head> body> ul> li>p>b>First Name:b> request.getParameter("firstName") %> p>li> li>p>b>Last Name:b> request.getParameter("lastName") %> p>li> ul> body> html>
Output
2. Read HTML forms select box (drop-down list) value in JSP
student-dropdown-form.html
html> head> title>Student Registration Formtitle> head> body> form action="student-dropdown-response.jsp"> First name: input type="text" name="firstName" /> br/>br/> Last name: input type="text" name="lastName" /> br/>br/> select name="country"> option>Braziloption> option>Franceoption> option>Germanyoption> option>Indiaoption> option>Turkeyoption> option>United Kingdomoption> option>United States of Americaoption> select> br/>br/> input type="submit" value="Submit" /> form> body> html>
Deploy this page on tomcat server and hit respective URL in the browser will display below form on the browser:
Let’s create a student-dropdown-response.jsp which will read above form data and display on a screen. Here is complete code in a page.
- We use request.getParameter() method to get the value of a form parameter.
- We can also use $ expression language to read the input value.
- We are using an expression tag to display a result.
html> head> title>Student Confirmation Titletitle> head> body> ul> li>p>b>First Name:b> request.getParameter("firstName") %> p>li> li>p>b>Last Name:b> request.getParameter("lastName") %> p>li> ul> br /> br /> The student's country: $param.country> body> html>
3. Read HTML Form’s radio button value data
student-form-radio.html
html> head> title>Student Registration Formtitle> head> body> form action="student-radio-response.jsp"> First name: input type="text" name="firstName" /> br/>br/> Last name: input type="text" name="lastName" /> br/>br/> Favorite Programming Language: br/> input type="radio" name="favoriteLanguage" value="Java"> Java input type="radio" name="favoriteLanguage" value="C#"> C# input type="radio" name="favoriteLanguage" value="PHP"> PHP input type="radio" name="favoriteLanguage" value="Ruby"> Ruby br/>br/> input type="submit" value="Submit" /> form> body> html>
Let’s create a student-radio-response.jsp which will read above form data and display on a screen. Here is complete code in a page.
- We use request.getParameter() method to get the value of a form parameter.
- We can also use $ expression language to read the input value.
- We are using an expression tag to display a result.
html> head>title>Student Confirmation Titletitle>head> body> ul> li>p>b>First Name:b> request.getParameter("firstName") %> p>li> li>p>b>Last Name:b> request.getParameter("lastName") %> p>li> ul> br/> br/> The student's favorite programming language: request.getParameter("favoriteLanguage") %> body> html>
Read HTML Form checkbox field value
student-checkbox-form.html
html> head> title>Student Registration Formtitle> head> body> form action="student-checkbox-response.jsp" method="post"> First name: input type="text" name="firstName" /> br/>br/> Last name: input type="text" name="lastName" /> br/>br/> input type="checkbox" name="favoriteLanguage" value="Java"> Java input type="checkbox" name="favoriteLanguage" value="C#"> C# input type="checkbox" name="favoriteLanguage" value="PHP"> PHP input type="checkbox" name="favoriteLanguage" value="Ruby"> Ruby br/>br/> input type="submit" value="Submit" /> form> body> html>
Deploy this page on tomcat server and hit respective URL in the browser will display below form on the browser:
student-checkbox-form.jsp
Let’s create a student-checkbox-response.jsp which will read above form data and display on a screen. Here is complete code in a page.
- We use request.getParameter() method to get the value of a form parameter.
- We can also use $ expression language to read the input value.
- We are using an expression tag to display a result.
Radio Button in JSP Page Example
Hey guys in this article, you will learn about creating the radio button and reading the radio button value in JSP with full code example.
- Check the Complete JSP Tutorials
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Javascript Projects for Beginners
- Check the Spring Boot JdbcTemplate Tutorials
Overview
To create a radio button in HTML we will use tag. It contains name attribute.
To read the radio button value in JSP, we will use the request object
getParameter() takes the name of the radio button. Another shortcut method to read radio button value is using param object
Using param object we can read the radio button value.
Complete Example
Follow the below steps to understand the complete example
Create a Project
You can check the following post to create a new Dynamic Web Project
Create a HTML form
Create EmployeeForm.html file under WebContent and add the following content
Create a JSP file
Create employee-details.jsp file under WebContent and add the following content
Employee details
First Name: $
Last Name: $
Country: $
Gender: $
Run the file
Right click on the File, choose Run As, choose Run on Server. It will open in a default web browser, you will see the following content
—
That’s it for this post, if you like this post, please share this post with your friends and collogues and also share this on your social media profiles.
Related posts:
About the author
Bushan Sirgur
Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.
How to use radio button in jsp page
This tutorial is about how to use radio button in jsp page.
How to use radio button in jsp page
How to use radio button in jsp page
This is detailed java code how to use radio button in jsp code and display a message in another jsp page according to selected radio buttons. First page in this example lets the user enter its name and select stream, branch and course type. On submission of the request, entered information is shown in the next page.
Save this code as a .jsp file named » first_page.jsp » in your application directory (‘user’, in our case) in Tomcat.
Congratulations !Welcome .
Stream Branch Course Type edit
Save this code as a .jsp file named » show_data .jsp » in your application directory (‘user’, in our case) in Tomcat.
To start Tomcat server, run startup.bat file from directory Tomcat-6.0.16/bin/startup.bat. To run this application open browser and type http://localhost:8080/user/first_page.jsp in address bar and hit enter key.
Fill Student name (For example, Mahendra Singh) and select stream, branch, course type according to student data then click submit button that will call another jsp page named » show_data.jsp», shows information of student that has been selected in first page.
To change or edit displayed information, click on link «edit».
Tutorials
- Creating a String
- Introduction to JSP
- Reading Request Information
- Introduction to the JSP Java Server Pages
- JSP FUNDAMENTALS
- Using Taglib in JSP. A brief introduction to taglibs and taglibs programing.
- JSP date example
- Reading Request Information
- Using Beans in JSP. A brief introduction to JSP and Java Beans.
- JSP 2.0 — New Features
- JSP Excel Tutorial
- Create Excel Sheet Using JSP
- Inserting Image In Excel Sheet Using JSP
- How to Create Excel Page Using JSP
- How to Create New Excel Sheet Using JSP
- Create Excel Sheet Using JSP
- Passing Various Data Types into Cells
- Assing Date into Cells
- Reading And Writing Excel File
- Selecting Excel Sheet File
- Zoom in Excel
- Zoom Out Excel
- Merging Two Cells
- Working With Fonts
- Working With Alignment Using JSP for Excel
- Shifting Row Using JSP
- Freeze And Split Pane
- Repeating Rows And Column
- different borders
- Create Shape in Excel Using JSP
- Creating Oval in Excel Using JSP
- Create Box in Excel Sheet Using JSP
- Filling Color in Excel Using JSP
- Set Font into TextBox String Using JSP
- Fit Hight Ad Wdth of Ecel Seet Uing JSP
- Setting Line Style
- Finding a Factorial using while loop
- JSP Simple Examples
- Calculate factorial Using Recursion
- Multiple Methods in Jsp