• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp logout button affects form

 
benedict goh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a form and a log out button but when i click on the submit button for the form my webpage redirects me to the log in
//the sessionvalidation
<%

if (session.getAttribute("user") != null) {
out.print(session.getAttribute("user"));
%>
<form >
<input type="submit"
onclick=<%
session.removeAttribute("user");%> >
</form>
<% }
String redirect="login.jsp";
response.sendRedirect(redirect);
}
%>
// the form affected
nric:
<select name="prefix">
<option value="S">S</option>
</select>
<input type="text" name="nric" >
<select name="suffix">
<option value="B">B</option>
</select>
<input type="hidden" value="validatenric" name="apptype">
<input type="submit" >


//the button in the form uses a webservice

<%
try {
qn1.Question1Service service = new qn1.Question1Service();
qn1.Question1 port = service.getQuestion1Port();
// TODO initialize WS operation arguments here

String nric=request.getParameter("nric");
String pre=request.getParameter("prefix");
String suff=request.getParameter("suffix");
char pref= pre.charAt(0);
char suffi= suff.charAt(0);

int num= Integer.parseInt(nric);
// TODO process result here
String result = port.checklength(num,pref,suffi);
out.println("Result = "+ result);

// TODO initialize WS operation arguments here
String apptype=request.getParameter("apptype");
port.addintodb(apptype);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing is that urgent.

Also use the code tags.



However this is your problem, you are trying to use java in a situaion where you can't.

With this code above the "user" attribute is removed from the session EVERY time this page loads.

You'll have to think a bit harder on the solution though I think your best plan is to start using servlets and remove all this java code from your JSP, it's messy and you end up having problems like this, where you think you can do something you can't.

[edited for emphasis]

Sean
 
benedict goh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah thank you for clearing that up for me.
Ops sorry i didn't notice the rules

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!