Note that there are some explanatory texts on larger screens.

plurals
  1. POspring/javaee custom 404 error-page not working
    primarykey
    data
    text
    <p>I am developing this Spring app where I "suddenly" decided to match error pages such as 404 (the famous HTTP 404 Not Found) to a more user friendly page.</p> <p>After quick research, I find that adding this code to <code>web.xml</code> does the trick</p> <pre><code> &lt;error-page&gt; &lt;error-code&gt;404&lt;/error-code&gt; &lt;location&gt;/error/404.jsp&lt;/location&gt; &lt;/error-page&gt; </code></pre> <p>Here we assume that I added the required <code>404.jsp</code> file to <code>/webapp/error/</code> directory.</p> <p>Related articles:</p> <ul> <li><a href="https://stackoverflow.com/questions/1495228/exclusive-url-patterns-in-tomcat-web-xml-descriptor">Exclusive url-patterns in Tomcat web.xml descriptor</a></li> <li><a href="https://stackoverflow.com/questions/1196569/custom-404-using-spring-dispatcherservlet">Custom 404 using Spring DispatcherServlet</a></li> </ul> <p>However after running the app and typing a random url (such as <code>http://localhost:8080/SpringWebApp/myRandomUrladasdad</code>) I find myself redirected to another standard 404 page - not mine.</p> <p>FYI this is my entire web.xml</p> <pre><code> &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;servlet&gt; &lt;servlet-name&gt;springapp&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;springapp&lt;/servlet-name&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;servlet&gt; &lt;servlet-name&gt;imageServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;sphbmveclp.account.controllers.ImageFromDirServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;imageServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/image/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;error-page&gt; &lt;error-code&gt;404&lt;/error-code&gt; &lt;location&gt;/error/404.jsp&lt;/location&gt; &lt;/error-page&gt; </code></pre> <p>After an unreasonnable amount of googling I ran into this:</p> <p><a href="http://www.mkyong.com/spring-mvc/404-error-code-is-not-working-in-spring-mvc/" rel="nofollow noreferrer">http://www.mkyong.com/spring-mvc/404-error-code-is-not-working-in-spring-mvc/</a></p> <p>So I assumed I had something good here. I assumed my vast <code>&lt;url-pattern&gt;/&lt;/url-pattern&gt;</code> may have been causing all this trouble. So I changed it to something more specific <code>&lt;url-pattern&gt;/admin/*&lt;/url-pattern&gt;</code> in this case.</p> <p>But no luck, It is still not working as expected.</p> <p>Any idea?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload