JSP Alert Example

By: Dorris Emailed: 1698 times Printed: 2194 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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>

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


1. View Comment

return false;
I'm not sure with the function of the above 2 lines. could anyone let me know how does it work

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

How to fetch a value from a database in dropdown based on the value selected in other dropdown in jsp? No ajax pl

View Tutorial          By: lara at 2014-11-19 09:02:43
3. View Comment

nice info 4me

View Tutorial          By: baru at 2015-07-24 08:52:03

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Dorris
sum of all digits in a given number using Shell Script
sh -x and sh -v in Linux
case..esac..in Linux Shell Script
while loop in Linux Shell Script
Nested for loop in Linux Shell Script
for loop in Linux Shell Script
Multilevel if-then-else in Linux Shell Script
Nested if-else-fi in Linux Shell Script
if...else...fi in Linux Shell Script
test command or [ expr ] in Linux Shell Script
if condition in Linux Shell Script
Download Linux. Which linux and where?
Formula in Hibernate
Primary keys assigned by triggers in Hibernate
Assigned identifiers in Hibernate

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP CheckBox Example
Comparison operators in JSP
Sending Email using JSP
JSP Alert Example
JSP Program for display Date
What are the different scopes in JSP?
The Advantages of JSP
Radio Object
Arithmetic Evaluation Using the Expression Language in JSP
JSP Example to connect to MS SQL database and retrieve records
Writing your first JSP page
Getting Started with JSP
JSP Directives
Form processing in JSP
A Simple Servlet Generating Plain Text
Most Emailed Articles (in JSP)
What is JSP?
The JSP Program running first Time.
Embedding java codes in jsp sciptlets
Scriptlets and Expressions in JSP
Sessions in JSP
Simple HTML-Building Utilities
Text Object
Server-side plug-Ins
The Response Object in JSP
Cookies using JSP or Java Bean
Click to Activate and Use this control
JSP pages in servlet
Declaring variable in JSP
Protecting your website with a login page