package com.sxt.servlet;
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.servlet.http.HttpSession;
import com.sxt.bean.Guser;
import com.sxt.dao.GuserDao;
import com.sxt.dao.impl.GuserDaoImpl;
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
String userpwd = request.getParameter("userpwd");
GuserDao dao = new GuserDaoImpl();
try {
Guser g = dao.login(username, userpwd);
PrintWriter out = response.getWriter();
// 判断是否登录成功
if(g!=null){
g.setUserpwd("");
HttpSession session = request.getSession();
session.setAttribute("g", g);
out.print("1");
}else{
out.print("0");
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}