i have made a small web application with
form.html
output.jsp
ServletOne.java
In the form.html,users enters his name and chooses a icecream flavour
both the username and icecream flavour are set as session attributes
these are displayed on output.jsp after processing by ServletOne.java
i am facing three problems:
1.session.isNew() returns true ,i have used sesssion ,then why is it still a new session
2. i am not able to use else in the jsp,getting syntax error on token
3.there is a log out button on the output.jsp
now i want that on clicking the log out button,the user should able to go out of session
can someone help
here are the files:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome</title>
</head>
<body>
<%String abc=(String)session.getAttribute("name"); %>
<%= "Welcome"+((String)session.getAttribute("textfield"))%></br>
<%= "You have choosen"+abc %>
<% if(session.isNew()) {%>
<% out.println("Wellllllllll"); %>
<%} %>
<% else {}%>
<form action="/ApplicationOne/Form.html" method="post" name="Logput">
<input name="Logout" type="submit" />
</form>
</body>
</html>
ServletOne.java
HttpSession session=req.getSession();
resp.setContentType("text/html");
PrintWriter pw=resp.getWriter();
String Icecream=req.getParameter("RadioGroup1");
session.setAttribute("name",Icecream );
session.setAttribute("textfield",req.getParameter("textfield"));
IceCream ob=(IceCream)getServletContext().getAttribute("icecream");
//pw.println("<html><body>");
//pw.println("Ice-Cream Flavour is"+ob.getFlavour());
//pw.println("Enjoy "+Icecream+"</html></body>");
session.setMaxInactiveInterval(1200);
RequestDispatcher view=req.getRequestDispatcher("/Output.jsp");
view.forward(req, resp);
form.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="/ApplicationOne/Welcome">
<p>
LoginID
<input type="text" name="textfield" />
<br/>
SELECT VALUE <br/>
<label>
<input type="radio" name="RadioGroup1" value="Vanilla" id="RadioGroup1_0" />
Vanilla</label>
<br />
<label>
<input type="radio" name="RadioGroup1" value="Chocolate" id="RadioGroup1_1" />
CHocholate</label>
<br />
<label>
<input type="radio" name="RadioGroup1" value="Strawberry" id="RadioGroup1_2" />
Strawberry</label>
<br />
<input type="submit" name="Submit" id="Submit" value="Submit" />
<br />
</p>
</form>
</body>
</html>
Probably because the server container has just created a new session. Take a look at the request and response headers and at your browser’s cookie cache. Is a session cookie being set? Does the session cookie keep changing?
Look at the Java code generated for the JSP and look for the syntax error there. The file will be some temporary directory in the web container directory tree.
You will need to do this in a servlet. The simple way would be to call
invalidateon the Session object. This may or may not work, depending on how your login mechanism / session cookie management is implemented.