响应sendRedirect给出404错误

时间:2011-03-28 05:06:25

标签: servlets weblogic

我试图在我的servlet代码中的某些条件下重定向到错误页面。但直到现在还没有任何结果。

所以我使用weblogic 10.x作为我的app服务器。我正在使用控制台将应用程序直接部署到托管服务器。

所以基本上我把它们装扮成.war文件并将它们部署为webapps。

   public void doGet (HttpServletRequest request, HttpServletResponse response)
      throws IOException , ServletException
   {
      try
       {
                  throw new Exception("503_Exception") ;                 
        }
        catch(Exception e)
        {
                  response.sendRedirect(response.encodeRedirectURL(HandleError.handle(e, request)));
       }
   }   


public class HandleError{
    public static String handle(Throwable t, javax.servlet.http.HttpServletRequest request)
    { 
         String sErrorMsg = t.getMessage();

         if (sErrorMsg.equals("503_Exception")) {
            request.setAttribute("msg", "INVALID SESSION");
            return "/jsp/error/custom.html";
         }
         return "/default_error.html";
    }
}

war文件结构

->jsp->error->custom.html
->web-inf
->web-inf->classes->project2->Class1.class

http:// machineNAME:3030 / Application3-Project2-context-root - >重定向到 - > http:// machineNAME:3030 / jsp / error / custom。 html - >>缺少实际上下文根的地方..

  

错误404 - 从RFC 2068找不到   超文本传输​​协议 -   HTTP / 1.1:   10.4.5 404 Not Found

     

服务器找不到任何东西   匹配Request-URI。没有   指示是否是   条件是暂时的或永久的。

     

如果服务器不想制作   这些信息可供使用   客户端,状态码403   (禁止)可以代替使用。该   应该使用410(Gone)状态代码   如果服务器知道,通过一些   内部可配置机制,   旧资源是永久性的   不可用,没有转发   地址。

但如果我给 -

response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + HandleError.handle(e, request)));

我得到错误310(net :: ERR_TOO_MANY_REDIRECTS):在chrome和FF错误中说重新指示太多

有人可以帮帮我吗? 提前致谢。 :)

1 个答案:

答案 0 :(得分:2)

在开头添加request.getServletContext().getContextPath()是一种很好的方法。但是你显然正在进入无限的重定向循环。不要忘记记录您的例外情况。因此,您将能够看到问题所在。

相关问题