主题:servlet 重定向问题
帮我看看下面的代码,为什么不能重定向啊???
package servlet.manager;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import question.admin.ManagerDAO;
import question.admin.ManagerVO;
public class Login extends HttpServlet {
private ManagerVO manager ;
public ManagerDAO managerdao ;
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
String userName = request.getParameter("userName") ;
String password = request.getParameter("password") ;
PrintWriter out = response.getWriter();
//out.print(userName);
manager = new ManagerVO() ;
this.manager.setUserName(userName) ;
this.manager.setPassword(password) ;
try
{
out.print(userName) ;
managerdao = new ManagerDAO();
managerdao.setManagerVO(manager) ;
if(managerdao.validate())
{
out.print(userName) ;
HttpSession session = null ;
session.setAttribute("managerid", managerdao.getManager().getManagerID());
response.sendRedirect("index.jsp") ;
}
else
{
request.setAttribute("error", managerdao.getMessage()) ;
response.sendRedirect("login.jsp") ;
}
}catch(Exception e)
{
e.printStackTrace() ;
}
}
}
没有语法错误,可response.sendRedirect不能执行
package servlet.manager;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import question.admin.ManagerDAO;
import question.admin.ManagerVO;
public class Login extends HttpServlet {
private ManagerVO manager ;
public ManagerDAO managerdao ;
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
String userName = request.getParameter("userName") ;
String password = request.getParameter("password") ;
PrintWriter out = response.getWriter();
//out.print(userName);
manager = new ManagerVO() ;
this.manager.setUserName(userName) ;
this.manager.setPassword(password) ;
try
{
out.print(userName) ;
managerdao = new ManagerDAO();
managerdao.setManagerVO(manager) ;
if(managerdao.validate())
{
out.print(userName) ;
HttpSession session = null ;
session.setAttribute("managerid", managerdao.getManager().getManagerID());
response.sendRedirect("index.jsp") ;
}
else
{
request.setAttribute("error", managerdao.getMessage()) ;
response.sendRedirect("login.jsp") ;
}
}catch(Exception e)
{
e.printStackTrace() ;
}
}
}
没有语法错误,可response.sendRedirect不能执行