JSP Alert Example

By: Dorris  

JSP Alert is used to put the validation on login page for the users. The example in this Tutorial provides you to create the validation on the login form using Javascript method in JSP page. 

The Tutorial illustrate an elaborative example to create alert box in a JSP page. We create a JSP file "AlertMessage.jsp". The Alert Message contains the code for User Login page that include the 'LoginName' and 'Password'. To apply validation we make use of javascript method in AlertMessage.jsp to validate the LoginName and password. The on submit button in JSP calls a JavaScript's function validLogin( ). The function validlogin ( ) is used to validate the username and password in JSP. If the username and password field is not inserted by the user then this will display error message using "alert()". The function also ensures that the field username and password must not be empty. Otherwise it will displays the message "Welcome User". 

AlertMessage.jsp

<html>
<head>
<script>
function validLogin(){
if (document.form.userName.value == ""){
alert ( "Please enter Login Name." );
document.loginform.userName.focus();
return false;
}
if (document.form.password.value == ""){
alert ( "Please enter password." );
document.userform.password.focus();
return false;
}
alert ( "Welcome User" );
return true;
}
</script>
</head>
<body>
<form name="form" method="post" onsubmit="return validLogin();">
<table width="250px" border=0 style="background-color:ffeeff;">
<tr><td colspan=2 align="center" style="font-weight:bold;font-size:20pt;" align="center">User Login</td>
</tr>
<tr><td colspan=2>&nbsp;</td>
</tr>
<tr><td style="font-size:12pt;" align="center">Login Name:</td>
<td><input type="text" name="userName" value=""></td>
</tr>
<tr><td style="font-size:12pt;" align="center">Password:</td>
<td><input type="password" name="password" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>



Archived Comments

1. Appreciating the hard work you put into your blog and detailed information you present.
It's

View Tutorial          By: home remedies for face at 2017-07-26 00:51:29

2. Kat6fgnhygaunc
View Tutorial          By: Kat6fgnhygaunc at 2017-07-12 18:24:54

3. This may be somewhat behind some of the quicker high-end phones available however
ample for

View Tutorial          By: how to jailbreak ipod at 2017-07-09 12:13:05

4. Every Year we spend hundreds for brand to us
Christmas/Holiday Decoration. By nature we love

View Tutorial          By: http://nmgsyfdc.com.cn at 2017-07-02 02:02:31

5. I'm truly enjoying the desijgn and layout of your site.
It's a very easy on the eyes which ma

View Tutorial          By: organic traffic at 2017-05-12 00:32:00

6. Usually I don't read post on blogs, but I wish
to say that this write-up very compelled me t

View Tutorial          By: stripper barcelona at 2017-05-02 16:46:15

7. Cidessenak
View Tutorial          By: Cidessenak at 2017-01-28 22:00:16

8. Someone necessarily help to make seriously articles I'd state. This is the very first time I frequen
View Tutorial          By: Smithk148 at 2017-01-10 02:53:57

9. nice info 4me
View Tutorial          By: baru at 2015-07-24 08:52:03

10. How to fetch a value from a database in dropdown based on the value selected in other dropdown in js
View Tutorial          By: lara at 2014-11-19 09:02:43

11. document.loginform.userName.focus();
return false;
I'm not sure with the function of t

View Tutorial          By: Parthiban at 2014-07-21 08:03:00


Most Viewed Articles (in JSP )

Latest Articles (in JSP)

Comment on this tutorial