Login page

how do i create a login page such that if username and password is wrong an error message is shown on page. if correct, another page is opened. I'm using form action="xxx.jsp" which opens the other page even if password is wrong.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

String usr="UserName";
String pwd="Password";
if(usr == pwd)
 out.print("same page");

 out.print("next page");

follow some of the links :

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi VbMonk,

To display MessageBox telling error message can be achieved using JavaScript. Let me give you some sample.

<script language="javascript">
function check()
    var form1 = document.myForm;
    if (form1["username"].value != form1["password"].value)
      alert('Username and password are wrong. They should be the same');
      location.href = "look.jsp";
<form name="myForm">
User name : <input type="text" name="username">
Password : <input type="text" name="password">
<input type="button" value="Submit" onclick="check()">


Hence, if you type the username to be different with the password, you will get error message. If you type in the same username and password, you will be directed to the look.jsp.

I hope this is what you want.


>if correct, another page is opened.

What happen if someone knows the private page's URL and accesses it directly from address bar without through the login page?
Have you planned for that hole?

In case of *you concern about that hole*, I recommend you to join with HTML, Servlet, Filter and Session.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.