- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个在独立 Tomcat 容器中运行的 Spring Boot 应用程序 - 我在使全局错误处理正常工作(自定义 404 页面等)方面一直在慢慢取得进展,并且 ErrorPageFilter
类是现在捕获错误,但它会抛出 NullPointerException
尝试将请求转发到 ErrorPage
。
堆栈跟踪如下:
java.lang.NullPointerException
org.springframework.boot.context.web.ErrorPageFilter.handleErrorStatus(ErrorPageFilter.java:141)
org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:112)
org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:59)
org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:101)
查看我所拥有的版本上的 ErrorPageFilter
源代码,尝试匹配错误路径的 RequestDispatcher
失败:
private void handleErrorStatus(HttpServletRequest request,
HttpServletResponse response, int status, String message)
throws ServletException, IOException {
if (response.isCommitted()) {
handleCommittedResponse(request, null);
return;
}
String errorPath = getErrorPath(this.statuses, status);
if (errorPath == null) {
response.sendError(status, message);
return;
}
response.setStatus(status);
setErrorAttributes(request, status, message);
request.getRequestDispatcher(errorPath).forward(request, response);
(最后一行是NPE)
我已配置错误处理如下,错误配置:
@Configuration
class ErrorConfiguration implements EmbeddedServletContainerCustomizer {
@Override public void customize( ConfigurableEmbeddedServletContainer container ) {
container.addErrorPages(new ErrorPage( HttpStatus.NOT_FOUND, "/errors/404" ))
container.addErrorPages(new ErrorPage( HttpStatus.INTERNAL_SERVER_ERROR, "/errors/500" ))
}
}
这似乎没问题 - 这些错误页面已注册并且 ErrorPageFilter
正在启动。
我尝试将路径“/errors/404”注册为标准 View Controller 和@Controller
请求映射(另请注意,如果我直接转到/errors/404在浏览器中解析 url 并显示页面)
有人能解释一下吗?
最佳答案
这是我的一个错误 - 是因为 web.xml 被意外删除而引起的 - 因此 RequestDispatcher 不可用。
添加 web.xml 解决了这个问题。
类似于行为:
关于java - Spring Boot - ErrorPageFilter 找不到 RequestDispatcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28168365/
我观察到虽然 RequestDispatcher.forward(request, response) 可以抛出 IllegalStateException(如果响应已提交),但 RequestDis
我已经阅读了很多类似的问题并尝试了所有建议的方法来解决问题,但是没有成功。现在我真的不知道如何处理这个 (localhost:8080/testWebApp/home): HTTP Status 50
使用 servletContext 而不是使用 request 来获取 requestDispatcher 有什么好处? servletContext.getRequestDispatcher(dis
处理RequestDispatcher时和资源路径,是主要基于 构建的路径元素?即使资源位于不同的包中 例如:我在 servlet 下定义了: /handlers/FrontHandler 以及
当我们使用请求调度程序方法 forward 将请求从一个 servlet 转发到另一个 servlet 时,以便另一个 servlet 生成响应,或者当我们希望另一个 servlet 的响应返回到一个
String fn=request.getParameter("fn"); request.setAttribute("eno",eno); RequestDispatcher rd = reques
我有这个搜索表单。 String search = request.getParameter("search"); if (search != null) {
我在 2 个桌面上安装了 2 个 apache tomee。第一个在 Windows 7 上,第二个在 Windows 8 上。当我部署我的应用程序(带有业务组件)时,发生了一些奇怪的事情。 我在我的
在 servlet 中,我们可以使用 requestdispatcher,它将从 servlet 转发到 servlet 或 html 文件。但是我在其余服务中尝试了这个 requestdispatc
我在学习 RequestDispatcher 时正在编写一些基本代码。我知道当调用 rd.forward() 时,控制(和响应处理)被转发到路径中命名的资源——在本例中是另一个 servlet。但是,
我正在尝试创建一个 HttpServlet,它将所有传入请求按原样转发到在不同域上运行的另一个 serlvet。 如何做到这一点? RequestDispatcher 的 forward() 仅在同一
如何在同一工作空间中将 RequestDispatcher 用于外部网络应用 在第一个网络应用程序中,我是这样使用它的 RequestDispatcher rd =request.getReques
在变量 search_for 中,我得到了我正在搜索的值的字符串值。但我无法通过 RequestDispatcher 将其传递给 jsp。我做错了什么? RequestDispatcher rd =
我正在使用 JAVA Servlet 开发网络应用程序。我正在尝试制作一个登录表单,我只想让用户设置用户名和密码,如果有效,则打开 mainPage.html代码运行时没有错误或异常,但是当此函数运行
我在 jsp 中遇到重定向问题,页面仍然存在并且不会抛出任何错误。 当我直接在 login.jsp 中编写脚本时,我可以进行重定向,例如 .......... 但是,当我将文件分成三个并包含它时
我正在使用 /* 将所有请求映射到一个 sevlet,我在其中完成所有身份验证工作。但我想跳过一些静态内容(如 css 文件)。所以我尝试从该 sevlet 到资源文件所在的位置 if(isResou
使用 RequestDispatcher 的主要目的是什么,例如当它在 Filter 中执行时,如下例所示: public void doFilter(ServletRequest request,
我有以下代码: RequestDispatcher dispatcher = request.getRequestDispatcher(viewName); // while viewName is
我正在阅读的所有在线引用资料和 head first JSP&Servlet 书都说明了 RequestDispatcher 和 Redirect(即 resoponse.sendRedirect()
如果我有一个 servlet,我可以毫无问题地转发到 WebContent 文件夹中的 jsp: request.getRequestDispatcher("page.jsp").forward(re
我是一名优秀的程序员,十分优秀!