package shiyan1;
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 shiyan1.Dao;
import shiyan1.Bean;
/**
* Servlet implementation class addServlet
*/
@WebServlet("/addServlet")
public class addServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public addServlet() {
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");
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("shenfen.jsp").forward(request, response);}
}catch(Exception e){
System.out.println("失败");
e.printStackTrace();
}
}