i need jsp and servlet coding for login page where the username and password must b stored in a db table
And I want vacation.
Sorry I thought that this thread was for posting what we want butyou won't get!
Seriously:
This thread is very old. If you have a question start your own. And no one is going to give you the code. We don't give code like that. If you don't have a clue start studying and search for examples in this forum. Post what you have done.
You need to know basic java, connecting to the database and running queries, sql, html and jsp. What do you know from the above?
And separate your methods in different classes. Don't put code that connects to the database in the jsp page.
Once you post what you have done you will get help.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
yup .. i learnt som servlet and jsp materials .and done the coding part... bt nw d prblm is on clckn d submit button itz not connecting d follwing pages... form actions also i changed ..m a bgnnnr in java ,, pls help me
I didn't understand anything from what you said. And don't expect any answers in this old thread, that the admins should close.
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Hi..
Saurv i create a login page on Mysql Database ...so u can change databse according you..
<%--
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="">
UserID : <input type="text" name="name" value="" size="20" />
Password : <input type="password" name="pass" value="" size="20" />
<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();
}
}
%>
Congratulations. You just posted exactly what you shouldNEVER do. You must never write code like that.
-- Not to mention that after a second look your code is wrong!
-- Not to mention that you did the other person's homework.
If ssaatt, you say that you have code post it in a new thread and avoid advice like the above.
No one ever bothers to do some searching? The question asked here has been answered so many times in this forum that there is a sticky post at the beginning of this forum that talks about MVC!
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448