session menagement in servlets explaion briefly?
Answer / abhijit dutta
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionSample extends HttpServlet {
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Step 1: Get the Session object
boolean create = true;
HttpSession session = request.getSession(create);
// Step 2: Get the session data value
Integer ival = (Integer)
session.getAttribute ("sessiontest.counter");
if (ival == null) ival = new Integer (1);
else ival = new Integer (ival.intValue () +
1);
session.setAttribute ("sessiontest.counter",
ival);
// Step 3: Output the page
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Session Tracking
Test</title></head>");
out.println("<body>");
out.println("<h1>Session Tracking Test</h1>");
out.println ("You have hit this page " + ival + "
times" + "<br>");
out.println ("Your " + request.getHeader("Cookie"));
out.println("</body></html>");
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
struts 1.3 features?
Difference between JSF Framework and Struts Framework.
13 Answers Accenture, BSS, IBM, TCS,
How is declarative handling of exceptions done in struts ?
What is the use of token interceptor in Struts2?
What is value stack?
how to develop the submit and search operations in single jsp using struts?
What does it cost to replace struts?
Which tag is used to declare constants in struts xml?
how the error can be showed in the jsp page in struts?
we have two applications A1 & A2 both are accesing the same databse table employee at the same time how we will manage this so that both application can get the correct no of emloyee while A1 is inserting a employee at the same time while other applicatuion is getting the empployee list.
collection framework hirarchy?
how many methods are there in RequestPrccesor class?