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 |
Where can i get jar file for use the struts-tags in struts2?
its a ActionForm controller or model?
16 Answers Patni, TCS, Wipro,
Is there a particularly good ide to use with struts?
What is the difference between RequestProcessor and RequestDispatcher?
11 Answers Ness Technologies, TCS,
How does struts2 token work?
What are the applications of struts?
What are action errors and error and what are the consequences they impose?
What do you mean by the abstract package in struts2, and what is its utilization?
How to handle exceptions in structs?
How do you find the struts version being used in a project?
What are best practices to follow while developing Struts2 application?
What is interceptor in Struts2?