I made a website using java servlets and JSP as well as HTML, CSS, and Javascript for the frontend, but for some reason, suddenly, all files except JSP and servlets are being ignored.
Basically, all my CSS, HTML, and Javascript files are being completely ignored so I just get what is on the JSP. I have literally no idea why. For styles, I am forced to use <%@ page contentType="text/css;charset=UTF-8" language="java" %>
. If I try to use a CSS file, I get css ignored due to mime type mismatch
from my browser.
In addition, the url must end with JSP or be a file mapping for a servlet to actually result in anything. If I visit mywebsite.com/page.html
, it doesn't take me to the page even though the html file exists. It only works for JSP or servlet file mapping.
Also, my 404 page only works for JSPs, but not servlets or any other file extension. mywebsite.com/page-that-doesnt-exist
or mywebsite.com/page-that-doesnt-exist.html
, takes me to my homepage instead of my 404 page. However, if I visit mywebsite.com/page-that-doesnt-exist.jsp
I do get redirected to my 404 page.
Just in case you thought this problem couldn't get any weirder, I found that CSS/HTML/any non-JSP files are not ignored if they are outside of the webapps folder, but they are ignored when they are in it.
Things I have Tried
Added
<mime-mapping><extension>css</extension><mime-type>text/css</mime-type></mime-mapping>
to myweb.xml
.Changing my welcome page's file mapping to something other than "/"
Going back to the default error page
My web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<welcome-file-list>
<welcome-file>homepage</welcome-file>
</welcome-file-list>
<context-param>
<param-name>DBusername</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>DBpassword</param-name>
<param-value>chirag12</param-value>
</context-param>
<context-param>
<param-name>uploadFilePath</param-name>
<param-value>/usr/share/websitestuff</param-value>
</context-param>
...
a ton of servlet mappings that I edited out
...
<servlet>
<servlet-name>CommentCreator</servlet-name>
<servlet-class>CommentUploader</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CommentCreator</servlet-name>
<url-pattern>/new-comment</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/404</location>
</error-page>
<servlet>
<servlet-name>testservlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testservlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>
Any help would be greatly appreciated because I don't understand this problem at all.