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.
VbMonkAsked:
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.

rk_radhakrishnaCommented:
<%
String usr="UserName";
String pwd="Password";
out.print(usr);
if(usr == pwd)
{
 out.print("same page");
}
else
{
response.sendRedirect("nextpage.jsp");


 out.print("next page");
}
%>

follow some of the links :
------------------------------
http://www.jsptut.com/
http://www.jspin.com/
0

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
suprapto45Commented:
Hi VbMonk,

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

test.jsp
--------
<html>
<title>testing</title>
<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');
    }
    else
    {
      location.href = "look.jsp";
    }
}
</script>
<body>
<form name="myForm">
User name : <input type="text" name="username">
<br>
Password : <input type="text" name="password">
<br>
<input type="button" value="Submit" onclick="check()">
</form>
</body>
</html>


look.jsp
---------
<html>
<title>Checking</title>
<body>
Good
</body>
</html>


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.

Regards
Dave
0
gnoonCommented:
VbMonk,

>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.
0
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
JSP

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.