JSP With JDBC
login.html
<html>
<body>
<form action="http://localhost/Hello/login.jsp" method="GET">
<table border="1">
<tr>
<th colspan="2">
Login Page with JSP
</th>
</tr>
<tr>
<td>
Name :
</td>
<td>
<input type="text" name="nm" value="">
</td>
</tr>
<tr>
<tr>
<td>
Password :
</td>
<td>
<input type="password" name="pw" value="">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="sub" value="Login"">
<a href="Registration.html">Registration</a>
</td>
</tr>
</table>
</form>
</body>
</html>
Registration.html
<html>
<body>
<form method="GET">
<table border="1">
<tr>
<th colspan="2">
Registration Page with JSP
</th>
</tr>
<tr>
<td>
Id :
</td>
<td>
<input type="text" name="id" value="">
</td>
</tr>
<tr>
<td>
Name :
</td>
<td>
<input type="text" name="nm" value="">
</td>
</tr>
<tr>
<td>
Email :
</td>
<td>
<input type="text" name="em" value="">
</td>
</tr>
<tr>
<td>
Password :
</td>
<td>
<input type="password" name="pw" value="">
</td>
</tr>
<tr>
<td>
Phone :
</td>
<td>
<input type="text" name="ph" value="">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="sub" value="Save" onclick="form.action='http://localhost/Hello/reg.jsp'">
<input type="submit" name="sub" value="Update" onclick="form.action='http://localhost/Hello/update.jsp'">
<input type="submit" name="sub" value="Delete" onclick="form.action='http://localhost/Hello/delete.jsp'">
<input type="submit" name="sub" value="View" onclick="form.action='http://localhost/Hello/view.jsp'">
<a href="Login.html">Login</a>
</td>
</tr>
</table>
</form>
</body>
</html>
insert.jsp
<%@ page import="java.io.*,java.sql.*" %>
<%
response.setContentType("text/html");
int id=Integer.parseInt(request.getParameter("id"));
String nm=request.getParameter("nm");
String em=request.getParameter("em");
String pw=request.getParameter("pw");
String ph=request.getParameter("ph");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DSN1");
PreparedStatement ps=con.prepareStatement("insert into regs values(?,?,?,?,?)");
ps.setInt(1, id);
ps.setString(2, nm);
ps.setString(3, em);
ps.setString(4, pw);
ps.setString(5, ph);
int i=ps.executeUpdate();
%>
<%@ include file="Registration.html" %>
<%
out.println("Insert Data SuccessFully...");
}
catch(Exception e)
{
out.println(e);
}
%>
Display.jsp
<%@ include file="Registration.html" %>
<%@ page import="java.sql.*,java.io.*" %>
<%
response.setContentType("text/html");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DSN1");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from regs");
out.println("<table border=1>");
out.println("<tr><th>Id</th><th>Name</th><th>Email</th><th>Password</th><th>Phone</th></tr>");
while(rs.next())
{
String id=rs.getString("Id");
String nm=rs.getString("Name");
String em=rs.getString("Email");
String pw=rs.getString("Pass");
String ph=rs.getString("Phone");
out.println("<tr><td>"+id+"</td><td>"+nm+"</td><td>"+em+"</td><td>"+pw+"</td><td>"+ph+"</td></tr>");
}
out.println("</table>");
}
catch(Exception e)
{
out.println(e);
}
%>
Comments
Post a Comment