[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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.
0
VbMonk
Asked:
VbMonk
3 Solutions
 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now