Loading
Request Scope

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  What is Request Scope ?


Ans)

There are three places a servlet can save data for its processing – in the request, in the session (if present), and in the servlet context (which is shared by all servlets and JSP pages in the context). Data saved in the request is destroyed when the request is completed. Data saved in the session is destroyed when the session is destroyed. Data saved in the servlet context is destroyed when the servlet context is destroyed.

Data is saved using a mechanism called attributes. An attribute is a key/value pair where the key is a string and the value is any object.

// Save and get a request-scoped value
req.setAttribute("userName", "testUser");
Object value = req.getAttribute("userName");

// Save and get a session-scoped value
HttpSession session = req.getSession(false);
if (session != null) {
    session.setAttribute("userName", "testUser");
    value = session.getAttribute("userName");
}

// Save and get an application-scoped value, could be accessed by all Servlets/Jsps in that web application
getServletContext().setAttribute("userName", "testUser");
value = getServletContext().getAttribute("userName");



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Request Scope


Request Scope

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free