Plz help me out for the source code in java for login-logout
I presume that by back button you are referring to a browser and you have implemented that with JSPs.
In that case when the username and password are correct, save the username in the session before you redirect to the next page. Then when you go to the next page (and every page) always take the username from the session and check if it is not null.
When you logout remove the username from the session, so when you hit the back button and try to get the username from the session it will be null. Then you can redirect the user to the login page
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
You can have the action be empty:
If you do that you will be redirected in the same page. Then at the beginning of the page before you start displaying any GUI check if the form was submitted and if it was do your validation and if it is correct redirect to the page you want.
Or else continue displaying the rest of the page
<%
String phone=request.getParameter("phone");
String user=request.getParameter("user");
if ((phone!=null)&&(user!=null)) {
if (phone.trim().length()==0) {
//error message
} else if (user.trim().length()==0) {
//error message
} else {
//do something with user and phone ....
//maybe use javascript to do the redirect
%>
<!-- I am not sure about this, you might want to check it out on your own at the site that I provide -->
<script>
window.open(....)
</script>
<%
}
}
%>
<body>
</body>
OR
you can send the action to a servlet, do the validation there and then redirect to the page you want. Code at the servlet to decide where you want to go:
RequestDispatcher dispatcher =
request.getRequestDispatcher(address);
dispatcher.forward(request, response);
OR
much better solution than the other two, use javascript, without submitting the form
instead of submit use a button, and do:
<input type="button" value="Submit" onclick="validate()">
Then in the tag write the validate() method using javascript and if all are correct submit the form
use: document.form1.submit()
For all the comments about javascript use: http://w3schools.com/
to learn javascript
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448