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
- Establishing the two-way Communication between Server and Client in Java
- Java Implementation of Deffi-Hellman Algorithm between Client and Server
- Creating an Server-Client Application using the DatagramPacket and DatagramSocket classes
- HTML | <data> Tag
- HTML | data value attribute
- HTML | data-* Attributes
- HTML | data Attribute
- HTML | DOM InputEvent data Property
- HTML | DOM Object data Property
- HTML | <object> data Attribute
- HTML | canvas ImageData data Property
- jQuery UI | Spinner to select numeric data
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.