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". 


function validLogin(){
if (document.form.userName.value == ""){
alert ( "Please enter Login Name." );
return false;
if (document.form.password.value == ""){
alert ( "Please enter password." );
return false;
alert ( "Welcome User" );
return true;
<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><td colspan=2>&nbsp;</td>
<tr><td style="font-size:12pt;" align="center">Login Name:</td>
<td><input type="text" name="userName" value=""></td>
<tr><td style="font-size:12pt;" align="center">Password:</td>
<td><input type="password" name="password" value=""></td>
<td><input type="submit" name="Submit" value="Login"></td>

Most Viewed Articles (in JSP )

Latest Articles (in JSP)

Comment on this tutorial

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. document.loginform.userName.focus();

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

2. How to fetch a value from a database in dropdown b
View Tutorial          By: lara at 2014-11-19 09:02:43

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

4. Someone necessarily help to make seriously article
View Tutorial          By: Smithk148 at 2017-01-10 02:53:57

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

6. Usually I don't read post on blogs, but I wish
View Tutorial          By: stripper barcelona at 2017-05-02 16:46:15

7. I'm truly enjoying the desijgn and layout of your
View Tutorial          By: organic traffic at 2017-05-12 00:32:00

8. Every Year we spend hundreds for brand to us

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

9. This may be somewhat behind some of the quicker hi
View Tutorial          By: how to jailbreak ipod at 2017-07-09 12:13:05

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

11. Appreciating the hard work you put into your blog
View Tutorial          By: home remedies for face at 2017-07-26 00:51:29