954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

Thankyou very much for ur early reply, I will try the precodure told by u, and ask u if i am unable to do so...

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

dhanshree
Newbie Poster
4 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

I am doing a project where there are many html forms to be filled by the user. Now i should retrieve the data from the form and insert it into the database. This all can i do with the help of JSP or Servlet? Which is the best?? How can i validate each and every field of the form e.g. is every field filled, do the phone no. filed have numbers in it , etc. How can i do it? Can u provide me a source code in java for this please??

dhanshree
Newbie Poster
4 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

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
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You