📄 registservlet.java
字号:
package servlet;
import bean.LessonBean;
import dao.DataAccess;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegistServlet extends HttpServlet {
private DataAccess regist;
/**
* Constructor of the object.
*/
public RegistServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String number=request.getParameter("sid");
if(regist.search(number)){
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>Regist</TITLE></HEAD>");
out.println(" <BODY><br><br>");
out.println("<center><h2>These are the courses you can selected</h2><br>");
out.println("<form action=\"addRegist.jsp\">");
out.println("<input type=\"hidden\" name=\"Sid\" value=\""+number+"\">");
out.println("<br><table border=1>");
out.println("<tr><th>Select</th>");
out.println("<th>Course ID</th>");
out.println("<th>Course name</th></tr>");
Vector<LessonBean> vector = regist.showCourse();
for(Iterator iter =vector.iterator();iter.hasNext();){
LessonBean lesson = (LessonBean)iter.next();
out.println("<tr><td>");
out.println("<input type=\"checkbox\" name=\"select\" value=\""+lesson.getLid()+"\"></td><td>");
out.println(lesson.getLid());
out.println("</td><td>");
out.println(lesson.getLname());
out.println("</td></tr>");
}
out.println("</table><br><br><br><input type=\"submit\" value=\"SUBMIT\">");
out.println("</form></center></BODY>");
out.println("</HTML>");
}else{
out.println("<HTML>");
out.println(" <HEAD><TITLE>Fail</TITLE></HEAD>");
out.println(" <BODY><h1>Sorry,your number is not right.</h1>");
out.println(" </BODY>");
}
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
regist = new DataAccess();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -