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 |
How do you know what to give for the "path " under in struts-config.xml ?
What do you mean by the abstract package in struts2, and what is its utilization?
What is apache struts used for?
What is the purpose of @element annotation annotation?
How to depoly your struts application in JBOSS
1 Answers HP, NuWare, Satyam, Wipro,
what is the difference between model1 and model2 architecture in struts?
What's mvc pattern ?
What are the two different types of validations that the validator framework supports?
What is MVC?
what is mean by custom tag?
wat happen when the connection is nt closed in jdbc n what vl happen when i interchange in executequery n execute statements
What is the purpose of @customvalidator annotation?