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 BeginnersMandatory 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
Advertisements
fieldsfields 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
validationvalidation 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
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 validationvalidation please help me to check
validation for
<form>
<table class="form">
<tr>
<td class="col1">
<label>Sno:</label>
</td>
<td
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 hashtablemultiple
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 filevalidation 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 informationValidation 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 fieldsJavascript 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: siva.ssk83@gmail.com
Regards,
S
Generating dynamic fields in struts2Generating 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 j2mehow 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
validation filesvalidation files If I place
validation files in the folder where the action classes are present,will there any error arise
spring form validationspring 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 strutsserver 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 codeJavascript
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 codeJavascript
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 validationjavascript 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 phpdropdown 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 validationform validation how the form
validation is done in jsf form using javaScript
Validation - StrutsValidation what is the best way to use
validation in Struts?either "validation.xml" or JavaScript
validation queryvalidation query where I should kept properties file inside struts Web application
NSURL ValidationNSURL Validation How to validate a NSURL string using special character
validation Html validationHtml validation How can I require that
fields be filled in, or filled in correctly
email validationemail validation during email
validation.... after domain name which it means if example example@gmail.co .... this address allowed by any
validation program .... but i want to show invalid email address because domain name com
email validationemail validation during email
validation.... after domain name which it means if example example@gmail.co .... this address allowed by any
validation program .... but i want to show invalid email address because domain name com
Validation of datepickerValidation 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