My brother Ravi Tamada request one mail about his college presentation. He is planning to do web dynamic project. So i am giving small explanation about JSP (Java Server Pages) to Mysql Connection structure, Tomcat directory structure and simple database examples.

Login.html

Code :
<body>
<form action="login.jsp" method="post">
User name :<input type="text" name="usr" />
password :<input type="password" name="pwd" />
<input type="submit" />
<form action="login.jsp" method="post">
User name :<input type="text" name="usr" />
password :<input type="password" name="pwd" />
<input type="submit" />
</form>
</body>Reg.html

code:
<form action="reg.jsp" method="post">
Email :<input type="text" name="email" />
First name :<input type="text" name="fname" />
Last name :<input type="text" name="lname" />
User name :<input type="text" name="userid" />
password :<input type="password" name="pwd" />
<input type="submit" />
</form>
Mysql Create Database Test:
Mysql no doubt about it best open source database http://mysql.com/

Create Table Users:

login.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String userid=request.getParameter("user");
session.putValue("userid",userid);
String pwd=request.getParameter("pwd");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/
test","root","root");
Statement st= con.createStatement();
ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'");
if(rs.next())
{
if(rs.getString(2).equals(pwd))
{
out.println("welcome"+userid);
}
else
{
out.println("Invalid password try again");
}
}
else
%>
reg.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=request.getParameter("userid");
session.putValue("userid",user);
String pwd=request.getParameter("pwd");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root","root");
Statement st= con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into users values ('"+user+"','"+pwd+"','"+fname+"',
'"+lname+"','"+email+"')");
%>
welcome.jsp
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=session.getValue("userid").toString();
%>
Registration is Successfull. Welcome to <%=user %>
Tomcat Directory Structure
Tomcat open source web server you can download from this link http://tomcat.apache.org/

Run Your Project














wat about the login.html and reg.html for these........sri?
i want to have those yaar............
plzz post those first sri......
.how to connect these jsp to html pages.........
hie srinivas,........plz explain how jsp and html pages get connected........plz post yaar.....!!
login.html and reg.html Code posted......
Simply stated, JDBC makes it possible to write platform independent Java programs that can be used to manipulate the data in a wide range of SQL databases without the requirement to modify and/or recompile the Java programs when moving from platform to platform or from DBMS to DBMS. MySQL is available for a wide variety of platforms.
its a nice post
very good this post. thanks
srinivas ur post was excellent..can you help me out with this..this user login when submit must go to another page that displays another html form.
@Harini
login.jsp include redirect .html
request.getRequestDispatcher("/xyz.html");
Where is Download button :)
Thanks this Connecting JSP To Mysql Database Lesson very useful to me!!!!!!
Hi Srinivas, I refer ur example for my application but i face on problem means getting an error so plz help me.
The exception is follow:
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
plz plz help me
Regards,
Mahesh
hi sir,
how to run this project in glassfish server.
i got the error as resources not available can u explan it clearly pls