import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Registration extends HttpServlet {
Statement st=null;
Connection con= null;
static final String url="jdbc:mysql://localhost:3306/gtu";
static final String user="root";
static final String pass="";
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String s1, s2, s3, s4, s5, sql;
s1 = request.getParameter("fname");
s2 = request.getParameter("lname");
s3 = request.getParameter("sem");
s4 = request.getParameter("C_no");
s5 = request.getParameter("erno");
sql = "Insert into student1 values('"+s5+"','"+s1+"','"+s2+"','"+s3+"', '"+s4+"')";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, pass);
st= con.createStatement();
int i= st.executeUpdate(sql);
out.println("<!DOCTYPE html>\n"
+ "<html lang=\"en\">\n"
+ "<head>\n"
+ " <meta charset=\"UTF-8\">\n"
+ " <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n"
+ " <meta name=\"viewport\" content=\"width=device-width, initial-
scale=1.0\">\n"
+ " <title> Registration</title>\n"
+ "</head>\n"
+ "<body>");
out.println("<h3>First Name : " + s1 + "</h3>");
out.println("<h3>Last Name : "+s2+"</h3>");
out.println("<h3>Semester : "+s3+"</h3>");
out.println("<h3>Contact Number : "+s4+"</h3>");
out.println("<h3>Enrollment no : "+s5+"</h3></body></html>");
out.println("<center>");
out.println("<a href=\"index.html\" style=\"font-weight: bolder;text-
decoration:none\">Back </a>");
out.println("<center>");
out.println("</body></html>"); }
catch(Exception e){
System.out.println(e.toString());
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
Search.
while(rs.next()){
out.print("<table >
<tr><td><b>Enrollment:</b></td><td> "+rs.getString(1)+"</td></tr>");
out.print("<tr><td><b>First
name:</b></td><td> "+rs.getString(2)+"</td></tr>");
out.print("<tr><td><b>Last
name:</b></td><td> "+rs.getString(3)+"</td></tr>");
out.print("<tr><td><b>Semester:</b></td><td> "+rs.getString(4)+"</td></tr>");
out.print("<tr><td><b>Contact
No:</b></td><td> "+rs.getString(5)+"</td></tr>");
}
out.println("</table>");
Full files
File 2https://drive.google.com/file/d/1gjp4dr-NFYNnN3EgKtfo1jwvK3H7iJi9/view?usp=drivesdk
No comments