Username: " name="description">


Home Answers Viewqa JSP-Servlet Login validation doubt

 
 


GRR
Login validation doubt
1 Answer(s)      2 years and 5 months ago
Posted in : JSP-Servlet

Hi,

1)login.jsp:

<%@page import="java.sql.*"%>

Username:
Password:

2)check.jsp:

<% String user=request.getParameter("user"); String pass=request.getParameter("pass"); if(user.equals("")&&pass.equals("")){ response.sendRedirect("login.jsp"); } else{ } %>

Once validating in check.jsp, i want error message on login.jsp like 'username or password is not provided' if username or password is null.

How get above thing.

View Answers

December 14, 2010 at 11:07 AM


Hi Friend,

Try the following code:

1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
  document.getElementById('lab1').innerHTML="<small><font color='red'>Enter Username!</font></small>";
  return false;
}
if(password==""){
  document.getElementById('lab2').innerHTML="<small><font color='red'>Enter Password!</font></small>";
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"><label id="lab1"></label></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"><label id="lab2"></label></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
<%String msg=request.getParameter("msg");
if(msg!=null){
    %>
<label><font color="red"><%=msg%></font></label> 
<%
}
    %>

2)check.jsp:

<%@page import="java.sql.*"%>

<%
String user=request.getParameter("user");
String pass=request.getParameter("pass");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where uname='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            out.println("welcome "+user);
          }
          else
          {
                       response.sendRedirect("login.jsp?msg=Invalid Username or Password");
          }
%>

Thanks









Related Pages:
Login validation doubt
Login validation doubt  Hi, 1)login.jsp: <%@page import="java.sql.*"%> Username: Password: 2)check.jsp: <% String user...(); ResultSet rs=st.executeQuery("select * from login where uname='"+user
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give
validation
validation  How to validate username and password in a login screen
Login page validation on ipad
Login page validation on ipad  I am using userId & password labels and their corresponding textfield. Now I want to validate the details by single sign in button and want to switch on to next page. Used two labels again
login page validation
login page validation  hi could you please send me code for login validations Email validation and password email should be in correct format and valid password in java   import java.awt.*; import javax.swing.
login form validation - JSP-Servlet
login form validation  hi, how to validate the login form that contains user name and password using post method . the validation should not allow user to login in the address bar thanks regards, anand
Login Password Validation iPhone / iPAD
Login Password Validation iPhone / iPAD  HOW TO WRITE A TEST CASE TO SET THE VALIDATION FOR LOGIN AND PASSWORD FIELD IN OBJECTIVE C, IOS.   @implementation LoginViewTests - (void)testPasswordFieldIsNotEmpty
struts2.2.1 Login validation example.
struts2.2.1 Login validation example. In this example, We will discuss about the Login validation using struts2.2.1. Directory structure of example...; charset=UTF-8"> <title>Login Validation Example<
Example of login form validation in struts2.2.1framework.
Example of login form validation in struts2.2.1 framework. In this example, we will introduce you to about the login form validation in struts2.2.1 framework. Our login form validation example does not validate the user against
LOGIN PROBLEM - JDBC
LOGIN PROBLEM   sir iam harikrishna studying B.Tech Fourth year sir i'm designing one website in that one i have to give facility as login id... and passowrd iam having doubt in that code sir iam doing the project
doubt this
doubt this  what is the use of "this" and "super" keyword
Jdbc Login Page Validation using Combobox
Jdbc Login Page Validation using Combobox  I got Login By this code i want to login by validating with combobox....The link which you send its without combobox.i m unable to get login by verifying with combo box..Ex banglore
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Jdbc Login Page Validation using Combobox
Jdbc Login Page Validation using Combobox  I am beginer to java i am.../html; charset=UTF-8"> <title>Celcabs Login Page</title> <...; <tr><td colspan="2"><input type="submit" value="Login"><
Jdbc Login Page Validation using Combobox
Jdbc Login Page Validation using Combobox  I am beginer to java i am.../html; charset=UTF-8"> <title>Celcabs Login Page</title> <...; <tr><td colspan="2"><input type="submit" value="Login"><
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
doubt in ejb3 - EJB
doubt in ejb3  hi i am new to ejb3 .i have written simple code which look like these entitybean package EntityBean; import java.io.Serializable... @Table(name="login") public class UserEntityBean implements Serializable
validation - Framework
validation  how to validate the action forms in struts? could you please explain how cross validation is done for date?  You go the following url: http://www.roseindia.net/struts/struts-login-form.shtml
JSP basic doubt
for validation like this: <%@page import="java.sql.*"%> <html> <script>
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
validation - Struts
validation  Hi, Can you give me the instructions about validations on server side in struts.i have done client side validations for login... information, http://www.roseindia.net/struts/struts-login-form.shtml Thanks
String Validation
String Validation changing password  Hi. I have a HTML coding...=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where password...=con.createStatement(); int i=st1.executeUpdate("update login set password
user validation
my final yr project in jsp.i m doin the login page & m stuck with a problem in validating the user.the code i hv written below doesnt redirect to the login...("Login again"); session.setAttribute("UserName", request.getParameter("UserName
String Validation
(); ResultSet rs=st.executeQuery("select * from login where password='"+currentPassword...=con.createStatement(); int i=st1.executeUpdate("update login set password='"+Newpass+"' where id
String Validation
(); ResultSet rs=st.executeQuery("select * from login where password='"+currentPassword...=con.createStatement(); int i=st1.executeUpdate("update login set password='"+Newpass+"' where id
Password validation
st=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where...)){ Statement st1=con.createStatement(); int i=st1.executeUpdate("update login set
Password validation
st=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where...)){ Statement st1=con.createStatement(); int i=st1.executeUpdate("update login set
Password validation
st=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where...)){ Statement st1=con.createStatement(); int i=st1.executeUpdate("update login set
Password validation
st=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where...)){ Statement st1=con.createStatement(); int i=st1.executeUpdate("update login set
Password validation
=st.executeQuery("select * from login where password='"+currentPassword...=st1.executeUpdate("update login set password='"+Newpass+"' where id='"+id
String Validation
(); ResultSet rs=st.executeQuery("select * from login where password...=con.createStatement(); int i=st1.executeUpdate("update login set password='"+Newpass
JSF Validation In Login Application
:view> <html> <head><title>JSF Simple Login Example<...;td><h:outputText value="Enter Login ID: " /></td> <... for the resultforfail.jsp file: Login Failed! Here is the code
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?
Struts Login Validation. In This code setter of login page is called only one...="com.credentek.recon.sms.action.IndexAction" method="login"> <...;action name="login" class="com.credentek.recon.sms.action.LoginAction">
Login form and registration
Login form and registration  I need a complete code for ligin and new user registration form and validation
Validation.... - JSP-Servlet
Validation....  in registration page. if i entered an Logine name , which all ready in the data base. how i can get the appropiate msg like "User all ready in the data base" in my data base User ID is the primary key and Login
PHP SQL Login Script
PHP SQL Login Script This Application illustrates how to create a php validation script for login application. In this example we create a login application where we put all php script for validation. In this application whether user
validation
validation  validation
jsp-oracle validation - JDBC
jsp-oracle validation  Dear friends, my validation not takes place... ----------------------------------- loginsuccess.jsp Logout Success login... database SQL> select * from login; USERID PASSWORD
STRUTS2.0 Validation Errors
STRUTS2.0 Validation Errors   <!DOCTYPE validators PUBLIC...; <param name="trim">true</param> <message>Login... Login Action class.and the Login form is using the default theme.Validation
Struts 2 Validation Example
; Validation Login application In this section we will write the code... code in our login application. For validation the login application java..., so our validation configuration file will be Login-validation.xml. The Login
Javascript validation - Java Beginners
Javascript validation  Hi, this is ragav and my doubt is: I am having a input type="file" text box in which the user can browse the required file.. If that file is a gif file, I have to allow user for further procession

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.