我这个servlet写的对吗
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
int num=Integer.parseInt(request.getParameter("num"));
String pwd=request.getParameter("pwd");
String sf=request.getParameter("sf");
add ad=new add();
if(sf.equals("教师")){
Teacher s=new Teacher();
s=ad.getStu(num, pwd);
System.out.println("aaaa");
if(s!=null){
HttpSession session=request.getSession();
session.setAttribute("username", s.getName());
request.getRequestDispatcher("index1.jsp").forward(request, response);
}else{
request.getRequestDispatcher("Lfaile.jsp").forward(request, response);
}
}
if(sf.equals("管理員")){
Manager m=new Manager();
m=ad.getMana(num, pwd);
if(m!=null){
HttpSession session=request.getSession();
session.setAttribute("username", m.getName());
request.getRequestDispatcher("index.jsp").forward(request, response);
}else{
request.getRequestDispatcher("Lfaile.jsp").forward(request, response);
}
}
}
[解决办法]
其实你可以将整个s对象放进session的
[解决办法]
确实,如楼上所说。教师的对象S可以整个放在session里面。一般我都是整个放的。要取出一些东西比较方便