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 declarative exception handling in struts?

0 Answers  


What is the role of action class?

0 Answers  


Which model components are supported by Struts?

0 Answers  


what are componeents presents in Strutsconfig.xml?

2 Answers   HCL,


What are the loop holes of struts?

0 Answers  






what are tiles in struts?

3 Answers   Wipro,


What are the 5 constants of action interface?

0 Answers  


What is the default location of result pages and how can we change it?

0 Answers  


What is the purpose of @after?

0 Answers  


I will explain the scenario now i have a form1 having some fields and i made it extends DynaActionForm. in struts config how can i specify another form form2 which has to extend the form1 please specify is it better to use actionform or dyna action form in applations. is dyna action form is comfortable in declaring form variables of type 'ArrayList<somegenerics>' extend the

0 Answers   Techno Solutions,


Struts follows which design patterns?

4 Answers   IGT,


Wat is Difference between Mvc1 architecture and Mvc2 Architecture?

21 Answers   HCL, IBM, Sanyaa Infotech,


Categories