My Java EE app is returning a 404 status when trying to load CSS and HTML files. Any ideas? Problem is happening with any browser, internal or external. The problem did not exist prior to editing a couple of JS files. In the process of troubleshooting JS files executions, I deleted and re-added my server and the problem has persisted ever since. All JS files are loading. The problem persists with deployment to the live website.
Add this to your web.xml
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
Related
This question already has an answer here:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 6 years ago.
When I go to http://localhost:8081/installer/index.xhtml via IE11 or Firefox45, I see only Setup Wizard and no JSF components. The HTTP status code is 200. I do not have any errors on Tomcat 7.
It is running without problem on JSF 1.2. I am only not sure about web.xml file.
Thanks in advance. Can you advise me what can be wrong, please?
EDITED
When I changed extension from .xhtml to .faces, I got an useful exception on Tomcat output, thanks.
Please check the servlet mapping in web.xml
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Now which url you are running like here servlet is called when i will run http://localhost:Port/Path/PageName.jsf but when i will try to run http://localhost:Port/Path/PageName.xhtml it will not work. Or I have to us like this http://localhost:Port/faces/Path/PageName.xhtml
What is the difference between creating .xhtml or .jsp .or .jsf for JSF pages
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
I'm building a web project and have the following code in my web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>-1</load-on-startup>
<enabled>true</enabled>
<async-supported>false</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
In eclipse markers window I see following error twice: The servlet mapping "Faces Servlet" refers to a servlet that is not defined. Well, in my opinion it is defined right there. When I delete servlet-mapping nodes, error disappears, but the project is useless. I've tried to re-validate project and web.xml file, refresh dependencies from maven. I haven't succeeded in finding anything relevant in google search. Also, I used very similar web.xml file in another project(not maven) and there it worked fine.
How can I fix this error?
I am having one spring project which is running with '*.htm' extension , we have bind it in web.xml file.
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
Now I want to integrate the Spring WebSocket and stomp js for the chat application, but the problem here is stomp.js is sending the request to the server without '.htm' extenstion.
due to which I am getting 404 error in each request (info or other xhr).
Is there any way to enable the Spring WebSocket and stomp js with '.htm' extension ?
I can't remove this extension it will hault my current application.
add prefix in the websocket url,it works well.
js:
var socket = new SockJS("/websocket_demo/myapp/ws");
web.xml DispatchServlet mapping:
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/myapp/*</url-pattern>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
You can add multiple servlet-mapping like this and keep the .htm working with "/url" serving for new functionality
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/url</url-pattern>
</servlet-mapping>
if you are using Servlet 2.5 you can directly use
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
<url-pattern>/url</url-pattern>
</servlet-mapping>
When I deploy my web application (Spring MVC) on WebLogic, the welcome page does not launch with the default URL http://my.site.com/myApp. I have my welcome page under home directory and I set as follows in web.xml.
<welcome-file-list>
<welcome-file>/home/index.html</welcome-file>
</welcome-file-list>
I am able to access the page using the full URL http://my.site.com/myApp/home/index.html.
Also, if I put index.html directly under the root and update web.xml as follows, the welcome page launches with the default URL
<welcome-file>/index.html</welcome-file>
What should I do to make the default URL launch the index.html under home directory ?
Here is the code in web.xml and applicationContext.xml.
web.xml:
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
applicationContext.xml:
<mvc:default-servlet-handler/>
I assume it has something to do with the leading slash. Have you tried simply home/index.html instead of /home/index.html.
This user asked the same question but had it work without the initial slash: can-i-set-tomcat-with-a-welcome-file-in-a-subfolder
Another discussion on the same topic:
I also had the same issue.
Make sure that the file you are trying to show is outside the
web-inf folder.
There are some configurations available in weblogic.xml file but none seems to work.I think it's a security feature or something else not sure exactly what.
In my case dispatcher servlet was capturing the empty request and showing no mapping found. May be you can create a controller mapping for the same and be done with it.
The funny thing is the same thing was working flawlessly in tomcat 7
I am using Spring MVC with such definition:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
But the problem that spring always trying to find /favicon.ico by default and as a result I can't render any page. How can I disable such behaviour?
Thank you
If you are using Spring Security, then make sure you have omitted the favicon request (and any other static resources) from the security filter chain.
It has nothing to do with spring mvc but that is the default behaviour of the browser you are using. Also that should not break anything at all and your app should work as normal even if it does not have an ico. (Unless you specifically coded to make it fail in case of missing ico)