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
- Parameter Passing Techniques in Java with Examples
- Java Implementation of Deffi-Hellman Algorithm between Client and Server
- HTML | <data> Tag
- HTML | data-* Attributes
- HTML | data Attribute
- HTML | <object> data Attribute
- HTML | DOM Object data Property
- HTML | DOM InputEvent data Property
- Java Servlet and JDBC Example | Insert data in MySQL
- Web ImageData API | ImageData.data property
- Sort an array of strings according to string lengths using Map
- Implementing Generic Graph in Java
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.