I have a simple form on a jsp page, as given below. On clicking the button, it should take us to a servlet by the name of LoginValidation. But it doesn't work.
<form name="login_form" action="LoginValidation" method="get" onsubmit="return func()" >
<input type="text" placeholder="Username" id="username" class="style-4" />
<input type="password" placeholder="Password" id="pass" class="style-4" />
<input type="submit" class="button" name="Sign_button" "/>
</form>
Here's func():
function func()
{
var filter="";
var uname = document.getElementById('username').value;
var pass = document.getElementById('pass').value;
if(uname==filter && pass==filter)
{
alert('Please enter your username and password to sign in.');
return false;
}
else if(uname==filter)
{
alert('Please enter your username to sign in.');
return false;
}
else if(pass==filter)
{
alert('Please enter your password to sign in.');
return false;
}
else
return true;
}
xml mapping (LoginValidation is in package Controller):
<servlet>
<servlet-name>LoginValidation</servlet-name>
<servlet-class>Controller.LoginValidation</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginValidation</servlet-name>
<url-pattern>/LoginValidation</url-pattern>
</servlet-mapping>
Basically, on login, func() runs. If value is true, it should ideally go to the LoginValidation servlet. But the function is not running as well. This same thing is running in another project of mine when I did it earlier. What am I doing wrong?
Tried out the code in a separate jsp, picking up sections and pasting them, removing extra div's. Seemed to make it work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.