javax.servlet.ServletException: AS-WEB-CORE-00089 servlet 异常
javax.servlet.ServletException: AS-WEB-CORE-00089 exception In servlets
我有一个名为 Document
的 servlet,我想将所有以 Document
开头的请求重定向到它,例如
http://localhost:8080/CollabEdit/Document/abcdwcklsclds
应该重定向到 servlet 文件。
所以,我使用了这样的注释:
@WebServlet("/Document/*")
但是,由于某些不明原因,它给出了一个异常:
javax.servlet.ServletException: AS-WEB-CORE-00089
这个异常在 Document.java 中,一旦我调用
就会抛出
request.getRequestDispatched("main.html").forward(请求, 响应) 。
否则也不例外。
然而,对于其他 servlet 中的相同请求,main.html 被调用得很好。
过滤器看起来不错。
您使用的是 Servlets 3.0
而不是旧版本吗?在旧版本中,您必须编辑 web.xml
。在 3.0 中,它必须看起来像 Post
Document
是否扩展 HttpServlet
?
您能否向我们展示更多您的代码,也许这样会更容易看出问题所在。
问候
一个forward
和一个redirect
不是同一件事。重定向允许您转到任何 URL,最终在另一台服务器上或使用另一种协议,因为您要求客户端查询 URL.
在转发中,您要求 servlet 容器将控制传递给同一应用程序(在同一上下文中)的另一个 servlet。当您使用相对路径时,您实际上是在请求什么是 servlet for : http://host.do.main/appname/Document/main.html
因为相对 URL 添加在当前页面地址的末尾(它甚至可以是 .../Document/.../main.html
)!
并且你 声明/Document
下的任何页面都应由Document
servlet 提供服务...所以无限循环...
您可以通过两种方式修复它:
- 如果你真的需要使用相对路径(它本质上是危险的,但你可能有理由这样做),尝试
../main.html
如果从 /Document
调用或 ../../main.html
如果调用来自 /Document/something
使用绝对路径:
contextPath = request.getContextPath();
request.getRequestDispatcher(contextPath + "/main.html").forward(request, response)
我有一个名为 Document
的 servlet,我想将所有以 Document
开头的请求重定向到它,例如
http://localhost:8080/CollabEdit/Document/abcdwcklsclds
应该重定向到 servlet 文件。 所以,我使用了这样的注释:
@WebServlet("/Document/*")
但是,由于某些不明原因,它给出了一个异常:
javax.servlet.ServletException: AS-WEB-CORE-00089
这个异常在 Document.java 中,一旦我调用
就会抛出request.getRequestDispatched("main.html").forward(请求, 响应) 。 否则也不例外。
然而,对于其他 servlet 中的相同请求,main.html 被调用得很好。
过滤器看起来不错。
您使用的是 Servlets 3.0
而不是旧版本吗?在旧版本中,您必须编辑 web.xml
。在 3.0 中,它必须看起来像 Post
Document
是否扩展 HttpServlet
?
您能否向我们展示更多您的代码,也许这样会更容易看出问题所在。
问候
一个forward
和一个redirect
不是同一件事。重定向允许您转到任何 URL,最终在另一台服务器上或使用另一种协议,因为您要求客户端查询 URL.
在转发中,您要求 servlet 容器将控制传递给同一应用程序(在同一上下文中)的另一个 servlet。当您使用相对路径时,您实际上是在请求什么是 servlet for : http://host.do.main/appname/Document/main.html
因为相对 URL 添加在当前页面地址的末尾(它甚至可以是 .../Document/.../main.html
)!
并且你 声明/Document
下的任何页面都应由Document
servlet 提供服务...所以无限循环...
您可以通过两种方式修复它:
- 如果你真的需要使用相对路径(它本质上是危险的,但你可能有理由这样做),尝试
../main.html
如果从/Document
调用或../../main.html
如果调用来自/Document/something
使用绝对路径:
contextPath = request.getContextPath(); request.getRequestDispatcher(contextPath + "/main.html").forward(request, response)