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 |
What do you mean by action errors and what are the results they force?
What are pull and push mvc architecture and which architecture does struts2 follow?
wahts the diif between Mvc1 and Mvc2?
Which interceptor is responsible for file upload support?
What are disadvantages of Struts?
wat happen when the connection is nt closed in jdbc n what vl happen when i interchange in executequery n execute statements
what is is the use DynaActionForm?
What is the role of action class in struts?
where you will implement the tiles in struts?
What is the purpose of plug-in tag in struct-config.xml?
What is the purpose of '@customvalidator'?
List the important attribute and elements of action mapping under struts.