packagecom.xk.servlet;importjava.io.IOException;importjava.io.UnsupportedEncodingException;importjava.util.ArrayList;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;//import javax.smartcardio.ResponseAPDU;
importcom.xk.bean.user;importcom.xk.bean.user1;importcom.xk.bean.user2;importcom.xk.bean.user3;importcom.xk.dao.Dao;/*** Servlet implementation class CourseServlet*/@WebServlet("/Servlet")public class Servlet extendsHttpServlet {private static final long serialVersionUID = 1L;publicServlet() {super();
}protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub//response.getWriter().append("Served at: ").append(request.getContextPath());
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String method= request.getParameter("method");if(method.equals("dopost"))
{
dopost(request,response);
}
}private void dopost(HttpServletRequest requst, HttpServletResponse response) throwsIOException, ServletException{
requst.setCharacterEncoding("utf-8");
String username= requst.getParameter("username");
String password= requst.getParameter("password");
String id1= requst.getParameter("id1");
System.out.println(username);
Dao dao=newDao();
user course= newuser(username,password,id1);
String id=dao.dopost(course);if(id.equals("0")) {
requst.setAttribute("message", "登录失败!");
requst.getRequestDispatcher("index.jsp").forward(requst,response);
}else if(id.equals("1")) {
requst.setAttribute("message", "登陆成功!");
requst.getRequestDispatcher("manager.jsp").forward(requst,response);
}else if(id.equals("2")) {
requst.setAttribute("message", "登陆成功!");
requst.getRequestDispatcher("teacher.jsp").forward(requst,response);
}else if(id.equals("3")) {
requst.setAttribute("message", "登陆成功!");
requst.getRequestDispatcher("student.jsp").forward(requst,response);
}
}protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub
doGet(request, response);
}
}