这个报错是什么原因?要怎么解决啊?
谢谢!!
public class Position extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
loginbean.hasAuthority(request, response);
Function.Location(request, response, "index.jsp");
}
}
loginbean.java中:
public static void hasAuthority( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
HttpSession session = request.getSession();
UserInfo user = (UserInfo)session.getAttribute( "session" );
if( user==null ) {
Function.Location(request, response, "login.jsp");
}
}
Function.java中
public static void Location( HttpServletRequest request, HttpServletResponse response, String Location )
throws ServletException, IOException
{
RequestDispatcher dispatcher = request.getRequestDispatcher( Location );
dispatcher.forward( request, response );
return;
}
就是这样喽,
程序本身应该不会有问题吧?
还请高手们指点指点
谢谢 !!
public class Position extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
UserInfo user = (UserInfo)session.getAttribute( \"session\" );String location = \"index.jsp\";
if( user==null ) {
location = \"login.jsp\";
}
RequestDispatcher dispatcher = request.getRequestDispatcher( location );
dispatcher.forward( request, response );
}
}
这样子自然不会报错,可这不是我的需求
其它的不说,先看这二段
HttpSession session = request.getSession();
UserInfo user = (UserInfo)session.getAttribute( "session" );
String location = "index.jsp";
if( user==null ) {
location = "login.jsp";
}
………………
RequestDispatcher dispatcher = request.getRequestDispatcher( location );
dispatcher.forward( request, response );
这两段之间是还有很有的代码要执行的,
你这样的话能完成登录判断的需求吗?
你不要告诉我中间的代码执不执行都不一样哦
再说了,那个判断函数在每个页面都要用,不封装起来不太好吧?
还有一个是问题的关键
在dopost里面调用的函数即loginbean.hasAuthority(request, response) 这个函数,
在这个函数里面有没有办法让doPost()提前结束?即不要执行这个函数以后的内容?
在这个函数里面加return的话只能提前结束这个函数,而不能结束doPost(),
还有一点我不明白的也是要说明的是:
我的这个程序是用NetBeans IDE 5.0开发的,NetBeans IDE 5.0 本身就有一个绑定的Tomcat 5.5.9, 在这个Tomcat的测试环境里我的这个程序是没有错的,一切正常,
但是我把它放在我单独安装的Tomcat 5.5.7里面就不行了,它会报错:Cannot forward after response has been committed
是不是在Tomcat里有哪些设置可以解决这个问题的?
还请高手指点,谢谢!