Suppose some data at the Server side has been created and now in order to pass that information in a JSP page, there is a need of request.getAttribute() method. This, in fact differentiates the getAttribute() and getParameter() methods. The latter is used to pass Client side data to a JSP.
1) First create data at the server side and pass it to a JSP. Here a list of student objects in a servlet will be created and pass it to a JSP using setAttribute().
2) Next, the JSP will retrieve the sent data using getAttribute().
3) Finally, the JSP will display the data retrieved, in a tabular form.
Servlet to create data and dispatch it to a JSP : StudentServlet.java
JSP to retrieve data sent by servlet “StudentServlet.java” and display it : stdlist.jsp
The Student.java class
Running the application
1) Run the servlet “StudentServlet.java”, which will pass student data to JSP page “stdlist.jsp”.
2) The JSP page “stdlist.jsp” retrieves the data and displays it in a tabular form.
Note : Entire application has been developed and tested on NetBeans IDE 8.1
Displaying Student Data : stdlist.jsp
- getParameter() - Passing data from client to JSP
- HTML | DOM getAttribute() Method
- Spring MVC with JSP View
- Program to validate a user using JSP
- Introduction to JSP
- Exception handling in JSP
- Environment setup for JSP
- Life cycle of JSP
- Difference between Servlet and JSP
- Directives in JSP
- JSP | Declaration Tag
- JSP | ScriptletTag
- JSP | Expression tag
- JSP | Implicit Objects - request and response
- JSTL | JSP Standard Tag Library
- Difference between JSP and ASP
- JSP Access Model
- How to display search result of another page on same page using ajax in JSP?
- Classes of JSP API
- Difference Between JSP and PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.