Week Prgms

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

WEEK 9:

Jdbc.jsp:

<%@ page language="java" import="java.sql.*"%>


<%@ page import="java.io.*"%>
<%Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn=null;
conn=DriverManager.getConnection("jdbc:mysql://localhost:8080/register","root","mysql");
ResultSet rs=null;
Statement stmt=conn.createStatement();
if(request.getParameter("action")!=null)
{
String studname=request.getParameter("name");
String studmail=request.getParameter("mail");
String studphone=request.getParameter("phone");
stmt.executeUpdate("insert into regtab(name,email,phone)
values('"+studname+"','"+studmail+"','"+studphone+"')");
rs=stmt.executeQuery("select * from regtab");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<h2>Student List</h2>
<table border="1">
<tr>
<td><b>No</b></td>
<td><b>UserName</b></td>
<td><b>E-Mail</b></td>
<td><b>Phone</b></td>
</tr>
<%int num=1;
while(rs.next()){
%>
<tr>
<td><%=num%></td>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("email")%></td>
<td><%=rs.getString("phone")%></td>
</tr>
<%
num++;
}
rs.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>
<%}else{%>
<html>
<head>
<title>Student regestration page</title>
<script language="javascript">
function validation(Form_obj){
if(Form_obj.name.value.length==0){
alert("PLease fill up the remaining information");
Form_obj.name.focus();
return false;
}
if(Form_obj.mail.value.length==0){
alert("PLease fill up the remaining information");
Form_obj.mail.focus();
return false;
}
if((Form_obj.phone.value.length==0)||(Form_obj.phone.value.length>10)){
alert("PLease fill up the remaining information");
Form_obj.studphone.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="jdbc.jsp" method="post" name="entry" onSubmit="return validation(this)">
<input type="hidden" value="list" name="action">
<table border="3">
<tr><td>
<table>
<tr>
<td colspan="2" align="center">
<h2>Student Entry Form</h2>
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td>Student Name:</td>
<td><input name="name" type="text" size="50"/></td>
</tr>
<tr>
<td>Student password:</td>
<td><input name="pwd" type="password" size="50"/></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="mail" type="text" size="50"/></td>
</tr>
<tr>
<td>Phone:</td>
<td><input name="phone" type="text" size="15"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit"/></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<%}%>
WEEK 10:

Login.html:

<html>
<head>
<title>Login Page</title>
</head>
<body bgcolor="gold" >
<form action="jsplog.jsp" method="post" >
<table align="center" >
<tbody >
<tr >
<th> <font color="BLACK" face="calibri">
User Name:<input type="text" name="name"/> </th></tr>
<tr >
<th><font color="BLACK" face="calibri">
Password:<input type="password" name="pass"/> </th></tr>
<tr align="center">
<td><input type="submit" value="Submit" /> </td>
<td><input type="reset" value="Reset" /> </td>
</tr>
<tr>
<td colspan="2" align="center"><a href="register.html">Sign Up</a></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

Register.html:

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="lightgreen" align="center">
<form action="jspreg.jsp" method="post" >

<table>
<tr><td>Name:</td>
<td><input type="text" name="name" /></td></tr>
<tr><td>Password:</td>
<td><input type="password" name="pass" /></td></tr>
<tr><td>Email id:</td>
<td><input type="text" name="eid" /></td></tr>
<tr><td>Ph. no:</td>
<td><input type="text" name="phno" /></td>></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Submit"
/></td></tr>
</table>
</form>
</body>
</html>

jsplog.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@ page language="java" import="java.sql.*" import="java.io.*" %>
<%
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/register";
con=DriverManager.getConnection(url,"root","vyasraju");
String name=request.getParameter("name");
String pass=request.getParameter("pass");
Statement s=con.createStatement();
ResultSet re=s.executeQuery("select * from user");
int c=0;
while(re.next())
{
if(name.equals(re.getString(1)) && pass.equals(re.getString(2)) )
{
c++;
out.write("valid user");
}
}
if(c==0)
out.write("invalid user");
}
catch(Exception e){
out.println(e.getMessage());
}
%>
Jspreg.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@page language="java" import="java.sql.*" import="java.io.*" %>
<%
Connection con=null;
ResultSet rst=null;
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/register";
con=DriverManager.getConnection(url,"root","vyasraju");
Statement st = con.createStatement();
String name=request.getParameter("name");
String pass=request.getParameter("pass");
String eid=request.getParameter("eid");
String phno=request.getParameter("phno");
String sql="insert into user(name,password,email,phoneno) values(?,?,?,?)";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1,name);
pst.setString(2,pass);
pst.setString(3,eid);
pst.setString(4,phno);
int numRowsChanged = pst.executeUpdate();
out.write("Congratulations!!! You have been successfully registered.");
}
catch(Exception e){
out.println(e.getMessage());
}
%>

You might also like