<%--
Document : Login1
Created on : Jul 1, 2011, 1:16:12 AM
Author : Dharmendra
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="com.p1.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><center>
<form action="">
<br>UserID : <input type="text" name="name" value="" size="20" />
<br>Password : <input type="password" name="pass" value="" size="20" />
<br><input type="submit" value="Login" />
</form>
</center>
</body>
</html>
<%
int x=0;
String s1=request.getParameter("name");
String s2=request.getParameter("pass");
out.print(s1+s2);
Connection con=null;
ResultSet rs=null;
PreparedStatement ps=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/dk","root","admin");
String sql="select *from login where userid=? and pass=?";
ps=con.prepareStatement(sql);
ps.setString(1, s1);
ps.setString(2, s2);
rs=ps.executeQuery();
if(rs.next()){
x=1;
}
RequestDispatcher rd=null;
if(x==1){
out.print("ok");
rd=request.getRequestDispatcher("home.jsp");
}
else{
out.print("Not ok");
rd=request.getRequestDispatcher("Login1.jsp");
}
rd.forward(request, response);
}catch(Exception e){
e.printStackTrace();
}
finally{
try{
rs.close();
ps.close();
con.close();
}catch(Exception ee)
{
ee.printStackTrace();
}
}
%>
dharma117
-6
Newbie Poster
Recommended Answers
Jump to PostCross posted in this thread:
http://www.daniweb.com/web-development/jsp/threads/75973Do you have a question?
The right way to do things:
http://www.daniweb.com/web-development/jsp/threads/141776The wrong way was just posted in this thread.
Jump to PostNo, I doubt he can because he simply copied and pasted it here from another post he saw elsewhere - which is why I have deleted it.
All 5 Replies
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
SagarSe7en
0
Junior Poster in Training
javaAddict
900
Nearly a Senior Poster
Team Colleague
Featured Poster
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
SagarSe7en
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.