Path with “WEB-INF” or “META-INF”
The spring boot error Path with “WEB-INF” or “META-INF” occurs when the jsp page url is invoked and the tomcat jasper dependency is not configured in the application. The jsp files are compiled and rendered using the tomcat embedded jasper maven dependency. If the maven dependency is not configured in the spring boot application, the “path with WEB-INF or META-INF” error will be shown in the console.
In the spring boot application, when you access a jsp page in browser, it shows “Whitelabel Error Page, There was an unexpected error (type=Not Found, status=404).” error in the browser. The exception to this is “HTTP 404 – page not found”. In the spring boot console log, the error is shown as ‘Path with ‘WEB-INF’ or ‘META-INF’.
The ResourceHttpRequestHandler class will throw the error as “o.s.w.s.r.ResourceHttpRequestHandler : Path with “WEB-INF” or “META-INF”:”
The exception stack trace will be shown below. This will be displayed in the console when a jsp page is invoked.
How to reproduce this issue
This error can be replicated in the mvc spring boot application. Follow the steps below to reproduce this issue. Create a spring boot mvc project in the Spring Tool Suite editor. Set up the jsp folder in the application.properties file as shown below.
Create a rest controller class to configure and invoke a url that will map to jsp file. Create a method in the controller class and configure the request mapping url to invoke. Configure a jsp file in the method that will be rendered when the url is invoked.
Servlet — Error Handling
A customized content can be returned to a Web client when a servlet generates an error. We can do that by adding elements in web.xml
The following table describes the elements we can use within an element.
|Optional||A valid HTTP error code, for example, 500|
Types of error a Servlet/Filter can throw
A servlet or filter may throw the following exceptions during processing of a request:
- Unchecked exceptions i.e. RuntimeException, Error and subclasses
- ServletException or subclasses
- IOExceptions or subclasses
All other exception should be wrapped in ServletException
Spring custom error with Java config
The Spring web framework allows Java developers to define a web-based application in a relatively easy way. Multiple features are provided to that matter: XML and Java-like configurations, handling the initialisation of a web application more easily, managing the data via controllers and so on.
This post documents how to define custom errors, for instance those with custom 404/not-found error pages. The information below is taken from my own experience and answer in StackOverflow.
Typically, the definition of a custom error page in Spring is documented as a change in the web.xml file. However, when using Java config, the configuration is likely to be way more complex. This post defines how to define a custom error page in a Spring web app that does not use XML-based configuration nor any other specific library for templates such as Thymeleaf.
The following files are defined or modified:
First, the SimpleMappingExceptionResolver is extended to handle any exception and process any output in the “ModelAndView” object. This class can be registered later in the configuration of the web application so that it acts as the default resolver.
Now, the custom exception resolved is registered as the default exception handler. More information can be defined, such as setting a mapping between any given exception – this can be done either importing it and providing the class name or by providing the full path via a string. Other operations are defining specific and default HTTP codes, default error views, setting the precedence of the processing and the like.
Now that the custom resolver is registered in the configuration of the web application, the object for the latter (the configuration via Java config) must be registered as well in the initialising class for the web application.
Tags and views
Besides the Java classes, there is content to be provided either as tags or views. In this example, we provide a tag file that can be parameterised in different views (one per error code), The structure of such files is as follows:
src/main/webapp/WEB-INF/tags/error.tag: a templated error tag to be used in the error views
src/main/webapp/WEB-INF/views/error/404.jsp: a 404 error-related template
src/main/webapp/WEB-INF/views/error/500.jsp: a 500 error-related template
src/main/webapp/WEB-INF/views/error/generic.jsp: a generic error template (for anything that does not fit the cases above and can be captured by the Spring framework)
With this, any error defined in CustomSimpleMappingExceptionResolver.java (that is, any exception or HTTP code or any other servlet request or response) and which can be caught (e.g., errors in JSTL templates are likely to not be intercepted) will be handled and a specific error page will be displayed instead of the custom web server error page.
Finally, a possibly good measure to combine with this is to turn off the debugging in the web server (e.g., example for Tomcat), so even under unexpected errors there will be no traces of information provided to the end user.
Technical guides, publications and snippets for easy deployment and development
Jetty/Howto/Custom Error Pages
THIS IS NOT THE DOCUMENTATION YOU ARE LOOKING FOR.
All development and stable releases are being performed with Jetty 9 and Jetty 10.
This wiki is now officially out of date and all content has been moved to the Jetty Documentation Hub
There are several ways to create custom error pages in Jetty that are described below.
Define error pages in web.xml
The standard webapp configuration file located in /WEB-INF/web.xml can be used to map errors to specific URLs with the element. This element creates a mapping between the error-code or exception-type to the location of a resource in the web application.
- error-code — integer value
- exception-type — fully qualified class name of a Java Exception type
- location — location of the resource in webapp relative to the root of the web application. Value should start with «/».
Error code example:
Context file configuration
Context files are normally located in /contexts/ (see ContextDeployer for more details). Context files can be used to configure the default error handler provided for a context with more flexibility than is available with web.xml, specifically with the support of error code ranges:
Custom error handler class
A context may be configured with a custom error handler class that extends either ErrorHandler for generic contexts, or ErrorPageErrorHandler for webapp contexts.
The following methods may be implemented to control the appearance of the error pages:
The ErrorPageErrorHandler can also be configured to suppress stacktraces by calling setShowStacks(false).
The custom error handler may be set on the context via the API or via a context configuration file. For example a custom error handling class can be added to the javadoc context with:
Server level 404 error
One may get a ‘page not found’ when a request is made to the server for a resource that is outside of any registered contexts. As an example, you have a domain name pointing to your public server IP yet no context is registered with jetty to serve pages for that domain. As a consequence, the server, by default, will give a listing of all contexts running on the server.
How do I get a friendly error page to replace the asp.net error page for url «WEB-INF./web.xml»?
This url is part of a pci compliance scan and it is flagging the very sparse asp.net error page returned, which on the live site is a 500 status code and the text
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
When running the site in visual studio I however get a 404 and the text
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /WEB-INF./web.xml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044
I’ve tried ignoring that url in routing and mapping it to our 404 route /error/not-found , we have custom errors on with a default redirect to /error/internal . I also tried using a location tag to deny access, blocking it with request filtering, and using a handler with that path to catch the request.
I tried this rewrite, also tried the same rule blocking and redirecting but I still get the same asp.net error page. The image cut off but the rule is ^.*\./.*$ and it does match the url I am trying to filter (I’ve also tried simply WEB-INF ).
Any idea how I can get this url to show our custom error page?