Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
Problem solved, I've not added the index.html. Which is point out in the web.xml
Note: a project may have more than one web.xml file.
if there are another web.xml in
src/main/webapp/WEB-INF
Then you might need to add another index (this time index.jsp) to
src/main/webapp/WEB-INF/pages/
404: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists with Tomcat
This is a common problem with application servers across the full spectrum. If you are encountering 404s or other issues, the way to debug the issue is to incrementally step backwards and forwards. The first thing you should do is look at your server logs to make sure the server has started right. If it has, you should try creating a index.html file and testing that. And so on and so on. On a failed test, you step back to see what's wrong in the previous steps. On a successful test, you step forward to see if the next thing works
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
the problem is in url pattern of servlet-mapping.
<url-pattern>/DispatcherServlet</url-pattern>
let's say our controller is
@Controller
public class HomeController {
@RequestMapping("/home")
public String home(){
return "home";
}
}
when we hit some URL on our browser. the dispatcher servlet will try to map this url.
the url pattern of our serlvet currently is /Dispatcher
which means resources are served from {contextpath}/Dispatcher
but when we request http://localhost:8080/home
we are actually asking resources from /
which is not available.
so either we need to say dispatcher servlet to serve from /
by doing
<url-pattern>/</url-pattern>
our make it serve from /Dispatcher by doing /Dispatcher/*
E.g
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
version="3.1">
<display-name>springsecuritydemo</display-name>
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/Dispatcher/*</url-pattern>
</servlet-mapping>
</web-app>
and request it with http://localhost:8080/Dispatcher/home
or put just /
to request like
http://localhost:8080/home
Spring Application gets 404 error on TomCat
I changed the JRE_HOME (was running java 8) to the same path of JAVA_HOME which is with Java 11, and it worked. Tomcat was on Java 8 and my project was running Java 11.
Log:Using JRE_HOME: "C:\Program Files\Java\jre1.8.0_333"
My POM.xml:<java.version>11</java.version>
Related Topics
How to Read JSON File into Java with Simple JSON Library
How to Sort an Arraylist of Objects by a Property
Instanceof - Incompatible Conditional Operand Types
What Objects How to Inject Using the @Context Annotation
How to Extract a Tar File in Java
What Is More Efficient: System.Arraycopy or Arrays.Copyof
Filter Values Only If Not Null Using Lambda in Java8
How to Redirect to Login Page When Session Is Expired in Java Web Application
Is Httpsession Thread Safe, Are Set/Get Attribute Thread Safe Operations
Concurrentmodificationexception When Adding Inside a Foreach Loop in Arraylist
Why I Can't Create an Array with Large Size
How to Reference Another Property in Java.Util.Properties