2011-03-28 95 views
0

我想在我的servlet代码中的某些条件下重定向到错误页面。但直到现在没有什么工作。响应sendRedirect给404错误

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

所以基本上我将它们打成.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"; 
    } 
} 

战争文件结构

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

HTTP://机器:3030/Application3-Project2的上下文根 - >重定向到 - >HTTP://机器:3030/JSP /error/custom.html - >>其中实际上下文根缺少..

错误404 - 未找到从RFC 2068 超文本Tr的ansfer协议 - HTTP/1.1: 10.4.5 404未找到

服务器没有找到任何匹配 Request-URI中。否 指示 条件是暂时的还是永久性的。

如果服务器不希望将此信息提供给 客户端,则可以使用状态码403 (禁止)。该 410(已删除)状态码应该是使用 如果服务器知道,通过一些内部 配置机制, 是一个古老的资源是永远不可 ,也没有转发 地址。

但是,如果我放弃 -

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

我得到错误310(净值:: ERR_TOO_MANY_REDIRECTS):铬和FF错误说太多重新方向

有人可以帮我吗? 在此先感谢。 :)

回答

2

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