今天双十二,是个事变的好日子。
package libraryservlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.SchoolDaoImpl;
import entity.School;
/**
* Servlet implementation class libraryservlet
*/
@WebServlet("/libraryservlet")
public class libraryservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public libraryservlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String ID=request.getParameter("username");
HttpSession session=request.getSession();
session.setAttribute("ID", ID);//存储数据
request.setAttribute("ID", ID);
String password=request.getParameter("password");
String method=request.getParameter("profession");
SchoolDaoImpl sd=new SchoolDaoImpl();
if("1".equals(method)) {
try{
System.out.println(1);
if("123456".equals(ID)&&"654321".equals(password)) {
response.getWriter().println("<script type='text/javascript'> alert('登录成功')</script>");
request.getRequestDispatcher("manage.jsp").forward(request, response);}
else {
response.getWriter().println("<script type='text/javascript'> alert('密码或账号错误')</script>");
request.getRequestDispatcher("library.jsp").forward(request, response);}
}catch(Exception e){
System.out.println("失败");
e.printStackTrace();
}
}
if("2".equals(method)) {
try{
System.out.println(1);
String stupass=sd.showstuname(ID);
if(password.equals(stupass)) {
SchoolDaoImpl sd1=new SchoolDaoImpl();
java.util.List<School> list=sd1.stushow(ID);
request.setAttribute("list", list);
response.getWriter().println("<script type='text/javascript'> alert('登录成功')</script>");
request.getRequestDispatcher("student.jsp").forward(request, response);}
else {
response.getWriter().println("<script type='text/javascript'> alert('账号或密码错误')</script>");
request.getRequestDispatcher("library.jsp").forward(request, response);}
}catch(Exception e){
System.out.println("失败");
e.printStackTrace();
}
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}