Answer Posted / 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 |
Post New Answer View All Answers
How can we display validation errors on jsp page?
Explain how can we upload files in struts2 application?
What are the ways in which duplicate form submission can occur?
What are the core classes of the struts framework?
What is includeaction?
What is an interceptor stack?
What is the difference between struts and spring? Explain
Can we use struts and spring together?
List some bundled validators?
State an example of struts configuration file as an action parameter for action servlet.
What is the purpose of struts.properties in struct2?
How can we integrate log4j in Struts2 application?
What are the two types of validations supported by validator framework?
Difference between html tags and struts specific html tags
What do you mean by a custom tag?