session menagement in servlets explaion briefly?



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

Post New Answer

More Struts Interview Questions

What is action class?

0 Answers  


What is the purpose of @keyproperty annotation annotation?

0 Answers  


What are the differences between Struts1 and Struts2 or how Struts2 is better than Struts1?

0 Answers  


What should be the name of xml file used for validation in struts?

0 Answers  


what is is the use DynaActionForm?

3 Answers   TCS,






Is struts thread safe?

4 Answers   HCL, Mphasis,


How struts2 supports internationalization?

0 Answers  


What does validation interceptor?

0 Answers  


What does i18n interceptor?

0 Answers  


What is the DynaActionForm? How we implement the dynaactionform ? can u please tell me the way to implement? in understandable way?

8 Answers   JBA Infotech,


What is the purpose of @conversion?

0 Answers  


What is the purpose of redirect result type?

0 Answers  


Categories