Servlets 响应sendRedirect给出404错误
我试图根据servlet代码中的某些条件重定向到错误页面。但到目前为止,一切都没有进展 所以我使用weblogic 10.x作为我的应用服务器。我使用控制台将应用程序直接部署到托管服务器中 所以基本上我把它们作为.war文件打包,然后作为webapps部署Servlets 响应sendRedirect给出404错误,servlets,weblogic,Servlets,Weblogic,我试图根据servlet代码中的某些条件重定向到错误页面。但到目前为止,一切都没有进展 所以我使用weblogic 10.x作为我的应用服务器。我使用控制台将应用程序直接部署到托管服务器中 所以基本上我把它们作为.war文件打包,然后作为webapps部署 public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException , ServletExcepti
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上下文根目录重定向到->http://machineNAME:3030/jsp/error/custom.html-->,其中缺少实际的上下文根
错误404--在RFC 2068中找不到
超文本传输协议--
HTTP/1.1:
10.4.5 404未找到
服务器没有找到任何东西
匹配请求URI。不
给出了以下指示,即
这种情况是暂时的或永久的
如果服务器不希望
此信息可供
客户端,状态代码403
(禁止)可以改为使用。这个
应使用410(已消失)状态代码
如果服务器知道,通过一些
内部可配置机制,
一个旧的资源是永久的
不可用且没有转发
地址
但如果我给-
response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + HandleError.handle(e, request)));
我收到错误310(net::ERR\u TOO\u MANY\u重定向):在chrome中,在FF错误中显示过多重定向
有人能帮我吗?
提前感谢。:) 在开头追加
request.getServletContext().getContextPath()
是一种很好的方法。但很明显,您正在进入一个无止境的重定向循环。不要忘记记录您的异常。这样你就能看到问题所在了