HTML file
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="RBServlet" >
Enter Student Name<input type="text" name="txtCust" ><br>
Enter Subject<input type="text" name="sub"><br>
Enter Marks<input type="text" name="txtMob" ><br>
<input type="reset" value="RE-ENTER"><input type="submit" value="SUBMIT">
</form>
</body>
</html>
RRBean.java
package mybeans;
import javax.ejb.Stateless;
import java.sql.*;
@Stateless
public class RRBean {
public RRBean(){}
public String markenter(String n, String s,String m){
String msg;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/rrdb","root","root123");
String query="insert into student1 values(?,?,?)";
PreparedStatement pst = con.prepareStatement(query);
pst.setString(1,n);
pst.setString(2,s);
pst.setString(3,m);
pst.executeUpdate();
msg="Marks entered";
}
catch(Exception e){msg=""+e;}
return msg;
}
}
RBServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ejb.EJB;
import mybeans.RRBean;
public class RBServlet extends HttpServlet {
@EJB RRBean obj;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String s=request.getParameter("sub");
String n=request.getParameter("txtCust");
String m=request.getParameter("txtMob");
String msg = obj.markenter(n, s, m);
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println(msg);
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet RBServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet RBServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
}
Comments
Post a Comment