The Wayback Machine - https://web.archive.org/web/20240922035254/https://www.geeksforgeeks.org/getattribute-passing-data-from-server-to-jsp/
Open In App

getAttribute() – Passing data from Server to JSP

Last Updated : 03 Dec, 2018
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

Implementation
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

Output
Displaying Student Data : stdlist.jsp
Displaying Student data


Previous Article
Next Article

Similar Reads

getParameter() - Passing data from client to JSP
The familiarity of the getParameter() method in getting data, especially form data, from a client HTML page to a JSP page is dealt with here. The request.getParameter() is being used here to retrieve form data from client side. Steps to be followed 1) First, a html page exGetParameter.html accepts data from the client. The client enters text in the
2 min read
Creating JSP in Eclipse IDE with Tomcat Server
Eclipse IDE is an open-source Integrated Development Environment that is popular for Java application development (Java SE and Java EE) and Android apps. It also supports C/C++, PHP, Python, Perl, and other web project developments via extensible plug-ins. JSP stands for java server pages. It is a server side technology been used for creating web a
3 min read
JSP - Server Response
In JavaServer Pages development, the server response refers to the data sent back to the client from the server after receiving and processing the client request, and the server response typically includes the dynamically generated by the HTML, XML, JSON, or other based on the JSP file logic and data. Key TerminologiesServer: The server is a comput
7 min read
Program to validate a user using JSP
Introduction to JSP : JSP(Java Server Page) is a server-side technology, used for developing webpages that support dynamic content. It enables the separation of dynamic and static content, thereby reducing development complexity. Developers are thus, armed with the power to insert java code in HTML pages by employing special JSP tags most of which
4 min read
Environment setup for JSP
The environment setup for JSP mainly consists of 3 steps: Setting up the JDK. Setting up the webserver (Tomcat). Starting tomcat server. All the steps are discussed in details below: Setting up Java Development Kit : Step 1: This step involves downloading JDK from Download JDK. Step 2: Setting up the PATH environment variable appropriately. For win
2 min read
Life cycle of JSP
A Java Server Page life cycle is defined as the process that started with its creation which later translated to a servlet and afterward servlet lifecycle comes into play. This is how the process goes on until its destruction. Following steps are involved in the JSP life cycle: Translation of JSP page to ServletCompilation of JSP page(Compilation o
2 min read
Difference between Servlet and JSP
Brief Introduction: Servlet technology is used to create a web application. A servlet is a Java class that is used to extend the capabilities of servers that host applications accessed by means of a request-response model. Servlets are mainly used to extend the applications hosted by web services. JSP is used to create web applications just like Se
3 min read
JSP | Implicit Objects - request and response
Perquisite: Introduction To JSPJSP stands for Java Server Pages, and it's a server side technology. It's used for creating web applications and dynamic web content. The main property of JSP is that we can insert our java code inside our HTML page using JSP tag. JSP provides you platform-independent pages. C/C++ Code <%@ page language = "jav
4 min read
Difference between JSP and ASP
JSP stands for Java Server Pages, a server-side scripting language which helps developers to create dynamic web pages based on HTML, XML or other types. It was created by Sun Micro systems. It's also similar to the ASP and PHP but it uses Java programming languages and it has the full access to Java APIs as well as databases. ASP stands for Active
2 min read
JSP Access Model
JSP is java based technology which is used to simplify the development of the dynamic webpage. JSP is used to separate the dynamic content of the web page from its content with the help of HTML and JSP tags. There are two JSP Model Architecture: JSP Model 1 Architecture: JSP Model1 Architecture or JSP Centric architecture contains JavaBeans or EJB
3 min read
How to display search result of another page on same page using ajax in JSP?
In this example, we are creating a search bar to display the result on the same page in using ajax in JSP. AJAX stands for Asynchronous JavaScript and XML. Where Ajax is mainly used for Displaying another web page content on the same web page without refreshment of the page. You can read more about ajax technology here. Approach: We use the JQuery
2 min read
Classes of JSP API
JSP API is a set of classes and interfaces that can be used to make a JSP page. These classes and interfaces are contained in the javax servlet.jsp packages. A portion of the classes characterized in the javax. servlet.jsp packages are: Error DataJSP WriterPage Context The Error Data Class: The error information class characterizes error data for e
4 min read
Difference Between JSP and PHP
JSP was an implies of giving a comparable programming fashion to PHP and ASP. It is based on Java Servlets and requires a Servlet holder server like Tomcat to supply the backend preparation required to change over the JSP to a servlet that can yield HTML. In differentiating PHP can run on its possess as a CGI motor, or as a coordinates module in nu
4 min read
What is JSP Filters?
JSP(Java Server Pages) is a server-side technology used to create web applications in Java. To manipulate the server's response and to intercept the requests from a client, JSP has its proprietary filters that are used with the help of a java class. At the same time, the filters are used to authenticate the credentials of the user and to perform da
4 min read
Difference between JavaScript and JSP
JavaScript is a lightweight and object-oriented scripting language used to create dynamic HTML pages with interactive effects within a webpage. It is an interpreted scripting language and its code is run in a web browser. It is also called a browser’s language and can be used for client-side developments as well as server-side developments. It was
3 min read
JSP Architecture
JSP architecture gives a high-level view of the working of JSP. JSP architecture is a 3 tier architecture. It has a Client, Web Server, and Database. The client is the web browser or application on the user side. Web Server uses a JSP Engine i.e; a container that processes JSP. For example, Apache Tomcat has a built-in JSP Engine. JSP Engine interc
3 min read
JSP Session - Implicit Object
In JSP, the session is the most regularly used implicit object of type HttpSession. It is mainly used to approach all data of the user until the user session is active. Methods used in session Implicit Object are as follows: Method 1: isNew(): This method is used to check either the session is new or not. Boolean value (true or false) is returned b
3 min read
JSP Config - Implicit Objects
JSP Config is an implicit object which is used to transmit the configuration details to the JSP page. In JSP, Config is an instance of type ServletConfig. This implicit object is used to acquire an initialization parameter for a certain JSP page. For each JSP page, the config object is generated through the web container. JSP's config object carrie
2 min read
JSP PageContext - Implicit Objects
PageContext extends JspContext to contribute helpful context details while JSP technology is applied in a Servlet environment. A PageContext is an instance that gives access to all the namespaces related to a JSP page, gives access to some page attributes and a layer over the application details. Implicit objects are connected to the pageContext co
4 min read
JSP Application - Implicit Objects
In JSP, application is an implicit object of type ServletContext. This is an instance of javax.servlet.ServletContext. It is generated onetime by the web container when web application or web project is deployed on server. This object is used to acquire the initialization parameter from the configuration file (web.xml). It is used for allotting the
3 min read
What is JSP Page?
A JSP page is a normal web page with JSP elements for generating the parts of the web page that differ for each request. A simple JSP web page that contains the JSP elements and template text. Everything on the page that is not a JSP element is called Template text. Template text can be any text, i.e., HTML, XML, WML or even plain text.JSP has no d
3 min read
Custom Tags in JSP
Custom tags are user-defined action tags that can be used within Java Server Pages. A tag handler is associated with each tag to implement the operations. Therefore, it separates the business logic from JSP and helps avoid the use of scriptlet tags. The scriptlet tag embeds java code inside the JSP page itself rendering the page difficult to unders
8 min read
Custom Tags with Body in JSP
A custom tag can be defined with its body. Body of the tag can be skipped or evaluated as per the requirement. Syntax of custom tags along with its body is given below: <prefix : suffix> body -content </prefix : suffix> To create custom tags with the body, the given steps need to be followed. 1. Create tag handler: Implement one of the
6 min read
JSP | Declaration Tag
Declaration tag is one of the scripting elements in JSP.This Tag is used for declare the variables. Along with this, Declaration Tag can also declare method and classes. Jsp initializer scans the code and find the declaration tag and initializes all the variables, methods, and classes. JSP container keeps this code outside of the service method (_J
2 min read
JSP | ScriptletTag
Java Server Page (JSP) is a technology for controlling the content or appearance of Web pages through the use of servlets. Small programs that are specified in the Web page and run on the Web server to modify the Web page before it is sent to the user who requested it. There are total three Scripting Element in JSP Scriptlet tagExpression tagDeclar
2 min read
JSTL | JSP Standard Tag Library
Introduction: Initially, Web designers used scriptlets in JSP pages to generate dynamic content. This resulted in readability issues and also made it difficult to maintain the JSP page. Custom tags were introduced to overcome the problems faced in using scriptlets. Although custom tags proved to be a better choice than scriptlets they had certain l
4 min read
JSP Full form
JSP stands for Jakarta Server Pages (formerly JavaServer Pages). It is a programming tool that is used on the Application Server Side to create dynamic web pages. JSP basically used to support Platform–Independent and Dynamic methods to build web-dependent applications based on HTML, XML, SOAP, etc. JSP allows developers to embed Java code as well
3 min read
Expression Language in JSP
Expression Language was introduced in JSP 2.0, it is a simplified language that is used to access and manipulate data within JSP pages also it provides a convenient way to access the data stored in objects like requests, sessions, applications, JavaBeans, etc. We know there are n number of objects that store data, and if we want to retrieve that da
4 min read
JSP - Custom URI in Custom Tag
JavaServer Pages (JSP) provide a dynamic environment for developing various online applications. Setting the custom Uniform Resource Identifiers (URIs) for custom tags opens up the way for management and organization. While the default pairing of JSP custom tags with URIs based on Java package structures lays the groundwork. Analysis of a few Aspec
6 min read
JSP - HTTP Status Codes
When the Client makes any requests to the server, the Status Codes are issued by the server as a response to the client's request. So, in an application, we have the client and the server architecture. The server is the part that holds the particular web service or an API. The client is the actor who sends that HTTP request to the server. So, whene
4 min read
Article Tags :