Mandatory Fields Validation

Mandatory Fields Validation

View Answers

October 23, 2008 at 10:55 AM

Hello,

you can do this through javascript.

Call a javascript function before submit the page.

Example.

<script>
function beforSubmit(){
if(document.formName.username.length <=0

||document.formName.password.length <=0 ){
}
}

</script>



in above code formName is name of the form and username is the name of the username textbox and passoword is name of the password textbox.

October 23, 2008 at 10:55 AM

Hello,

you can do this through javascript.

Call a javascript function before submit the page.

Example.

<script>
function beforSubmit(){
if(document.formName.username.length <=0

||document.formName.password.length <=0 ){
}
}

</script>



in above code formName is name of the form and username is the name of the username textbox and passoword is name of the password textbox.

October 23, 2008 at 12:42 PM

Hi friend,

<html>
<title>login application in jsp</title>
<head>

<script type="text/javascript">

function validateForm(theForm){



if(theForm.userid.value==""){

//Please enter username

alert("Please enter User Name.");

theForm.userid.focus();

return false;

}
if(theForm.password.value==""){
//please enter passward
alert("Please enter Password.");
theForm.password.focus();
return false;
}

return true;
}
</script>
</head>

<body>
<br>
<br/>
<center>

<table border="1" width="400px" bgcolor="pink" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<form method="POST" action="loginAction.jsp" onsubmit="return validateForm(this);">

<h2 align="center"><font color="red">Login Application in JSP</font></h2>
<table border="0" width="350px" cellspacing="2" cellpadding="4">
<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><input type="text" name="userid" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Password:</b></td>
<td width="50%"><input type="password" name="password" size="20"/> </td>
</tr>

</table>
<center>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</center>
</form>
</td>
</tr>
</table>
</center>
</body>

</html>

October 23, 2008 at 12:45 PM

form,

<html>
<title>login application in jsp</title>
<head>

<script type="text/javascript">

function validateForm(theForm){



if(theForm.userid.value==""){

//Please enter username

alert("Please enter User Name.");

theForm.userid.focus();

return false;

}
if(theForm.password.value==""){
//please enter passward
alert("Please enter Password.");
theForm.password.focus();
return false;
}

return true;
}
</script>
</head>

<body>
<br>
<br/>
<center>

<table border="1" width="400px" bgcolor="pink" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<form method="POST" action="Login" onsubmit="return validateForm(this);">

<h2 align="center"><font color="red">Login Application in JSP</font></h2>
<table border="0" width="350px" cellspacing="2" cellpadding="4">
<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><input type="text" name="userid" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Password:</b></td>
<td width="50%"><input type="password" name="password" size="20"/> </td>
</tr>

</table>
<center>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>
</center>
</form>
</td>
</tr>
</table>
</center>
</body>

</html>


October 23, 2008 at 12:46 PM

Here is the servlet code.

package javacode;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;

public class Login extends HttpServlet{

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String dbName = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName = "amar";
String password = "amar123";

String username="";
String userpass="";
String strQuery= "";
Statement st=null;
ResultSet rs=null;
HttpSession session = request.getSession(true);

try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
if(request.getParameter("userid")!=null &&
request.getParameter("userid")!="" && request.getParameter("password")!=null &&
request.getParameter("password")!="")
{
username = request.getParameter("userid").toString();
userpass = request.getParameter("password").toString();
strQuery="select * from login where userid='"+username+"' and password='"+userpass+"'";
System.out.println(strQuery);
st = conn.createStatement();
rs = st.executeQuery(strQuery);
int count=0;
while(rs.next()) {
session.setAttribute("userid",rs.getString(2));
count++;
}
if(count>0)
{
response.sendRedirect("welcome.jsp");
}
else{
response.sendRedirect("servletLoginPage.jsp");
}

}
else {
response.sendRedirect("servletLoginPage.jsp");
}

System.out.println("Connected to the database");

conn.close();
System.out.println("Disconnected from database");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
------------------------------

Visit for more information.

http://www.roseindia.net/servlets/

Thanks









Related Tutorials/Questions & Answers:
Mandatory Fields Validation - Java Beginners
Mandatory Fields Validation  In my login servlet, i have fields username and password. I would like a message to be displayed when both or one field has been left blank. Please help  Hello, you can do this through
Server side validation on dynamically generated fields from more than one table on spring framework.
Server side validation on dynamically generated fields from more than one table on spring framework.   Server side validation on dynamically generated fields from more than one table in spring mvc framework
Advertisements
fields
fields  hi.create a class named librarybook that contains fields to hold methods for setting and getting a librarybooks title,author, and page count
Is Java mandatory for big data?
Is Java mandatory for big data?  Hi, I am beginner in Data Science... mandatory for big data? Try to provide me good examples or tutorials links so that I can learn the topic "Is Java mandatory for big data?". Also
ModuleNotFoundError: No module named 'odoo11-addon-product-code-mandatory'
ModuleNotFoundError: No module named 'odoo11-addon-product-code-mandatory' ...: ModuleNotFoundError: No module named 'odoo11-addon-product-code-mandatory' How to remove...-mandatory' error? Thanks   Hi, In your python environment you have
ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory'
ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory' ...: ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory' How to remove...-mandatory' error? Thanks   Hi, In your python environment you have
ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory'
ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory' ...: ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory' How to remove...-mandatory' error? Thanks   Hi, In your python environment you have
ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory'
ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory' ...: ModuleNotFoundError: No module named 'odoo12-addon-product-code-mandatory' How to remove...-mandatory' error? Thanks   Hi, In your python environment you have
validation
validation  validation
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
ModuleNotFoundError: No module named 'odoo10-addon-stock-operation-package-mandatory'
-mandatory'  Hi, My Python program is throwing following error...-mandatory' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-stock-operation-package-mandatory' error? Thanks   Hi
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class="col1"> <label>Sno:</label> </td> <td
upload image and fields.....fields is id name.....
upload image and fields.....fields is id name.....  Get Data using Java Servlet The frame takes following input.. Id: Name: browse:Image are file
upload image and fields.....fields is id name.....
upload image and fields.....fields is id name.....  Hi this is sreenu my problam is capcharing data to the servler thi is my frame Id: Name: browse:Image are file
ModuleNotFoundError: No module named 'fields'
ModuleNotFoundError: No module named 'fields'  Hi, My Python... 'fields' How to remove the ModuleNotFoundError: No module named 'fields'... to install padas library. You can install fields python with following command
multiple fields in hashtable
multiple fields in hashtable  Hai,could anyone help me to implement the object car fields speed,make & color in Hash table
validation in struts2 using .xml file
validation in struts2 using .xml file  how to do xml validation in struts2 on dynamic fields   Hello Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/struts/struts2/struts2validation
Validation for customer information
Validation for customer information  hi.... I have created one jsp page which contains customer infomation such as name,city,emailid,mobileno,date of birth.I want to do validation for all these fields using javascript....customer
Javascript Code for all fields
Javascript Code for all fields  Good Evening Sir/Madam, Please send me the example program using bootstrap framework for all fields of a form. Please send me the javascript code My E-mail id: [email protected] Regards, S
Generating dynamic fields in struts2
Generating dynamic fields in struts2  Hi, I want generate a web page which should have have some struts 2 tags in a group and a "[+]" button for the group. On click of this button one more group of fields should be generated
how to add fields at runtime in j2me
how to add fields at runtime in j2me  How can I add fields at runtime in my form? How can I switch screens and can add fields at runtime? Thanks Dhruv
ModuleNotFoundError: No module named 'asymm-fields'
ModuleNotFoundError: No module named 'asymm-fields'  Hi, My Python... 'asymm-fields' How to remove the ModuleNotFoundError: No module named 'asymm-fields' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'meta_fields'
ModuleNotFoundError: No module named 'meta_fields'  Hi, My Python... 'meta_fields' How to remove the ModuleNotFoundError: No module named 'meta_fields' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'misc_fields'
ModuleNotFoundError: No module named 'misc_fields'  Hi, My Python... 'misc_fields' How to remove the ModuleNotFoundError: No module named 'misc_fields' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'pylint-fields'
ModuleNotFoundError: No module named 'pylint-fields'  Hi, My... 'pylint-fields' How to remove the ModuleNotFoundError: No module named 'pylint-fields' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pylint-fields'
ModuleNotFoundError: No module named 'pylint-fields'  Hi, My... 'pylint-fields' How to remove the ModuleNotFoundError: No module named 'pylint-fields' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'asymm-fields'
ModuleNotFoundError: No module named 'asymm-fields'  Hi, My Python... 'asymm-fields' How to remove the ModuleNotFoundError: No module named 'asymm-fields' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-fields'
ModuleNotFoundError: No module named 'django-fields'  Hi, My... 'django-fields' How to remove the ModuleNotFoundError: No module named 'django-fields' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-fields'
ModuleNotFoundError: No module named 'python-fields'  Hi, My... 'python-fields' How to remove the ModuleNotFoundError: No module named 'python-fields' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'custom-fields'
ModuleNotFoundError: No module named 'custom-fields'  Hi, My... 'custom-fields' How to remove the ModuleNotFoundError: No module named 'custom-fields' error? Thanks   Hi, In your python
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
Version of com.jidesoft>jidefx-fields dependency
List of Version of com.jidesoft>jidefx-fields dependency
spring form validation
spring form validation  how can we validate a web form using spring, try to give an example of the form containing some fields and their validations,ASAP......   Please visit the following link: Spring form validation
server side validation in struts
server side validation in struts  Hello sir, i want to do server side validation in struts based on 3 fields. those 3 field are BatchNo,LotNo,StepNo.Here we can have the same batchno,lotno for different forms
Javascript validation code
Javascript validation code  Hi, I need a javascript validation code for the following fields 1)Name 2)Email 3)Mobile 4)City 5)State 6)Product type 7)submit button All should display enter the field required(like name required
Javascript validation code
Javascript validation code  Hi, I need a javascript validation code for the following fields 1)Name 2)Email 3)Mobile 4)City 5)State 6)Product type 7)submit button All should display enter the field required(like name required
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
Fields in java class
Fields in java class       In this section, we will explore the concept of the fields in the reference of object oriented programming techniques. There are two part of the field
dropdown list and text fields in php
dropdown list and text fields in php  How could I use php to populate text fields by selecting a name of a business from dropdown list? Those text fields that will be populated by information in regards its company name, suite
form validation
form validation  how the form validation is done in jsf form using javaScript
Validation - Struts
Validation  what is the best way to use validation in Struts?either "validation.xml" or JavaScript
validation query
validation query  where I should kept properties file inside struts Web application
NSURL Validation
NSURL Validation  How to validate a NSURL string using special character validation
Html validation
Html validation  How can I require that fields be filled in, or filled in correctly
email validation
email validation  during email validation.... after domain name which it means if example [email protected] .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
email validation
email validation  during email validation.... after domain name which it means if example [email protected] .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
Validation of datepicker
Validation of datepicker  I have a datepicker in my JSp...the seleted dates are put in a text box. I want the alert the user from selecting future... a future date is entered..How to do this validation in javascript or jsp

Ads