Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
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");
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.