简体   繁体   中英

Deploying a webapp under ROOT - index.html not displaying

I am using tomcat7 and have a small Java application that needs to be deployed under ROOT. The reason for this has to do with the client's inability to specify the webapp's proper context path at this time.

I have an index.html in this webapp and my issue is that when I deploy the application under the webapp name - ${catalina_home}/mywebapp - the index.html renders without a problem when I navigate to http://localhost:8080/mywebapp .

However, when I deploy it under ROOT - ${catalina_home}/ROOT - the index.html inside does not render when I navigate to http://localhost:8080/ . The error is 404 not found. Does this have anything to do with overriding tomcat's default page?

My web.xml:

<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/</param-value>
</context-param>

...
<servlet-mapping>
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

...

Can someone explain why this is so?

Thanks in advance.


UPDATE: I see in this stackoverflow Display html page in tomcat from maven RESTEasy webapp that the issue may be that my filter says anything under /* should go to the servlet. I tried to set up a default servlet for .html pages, but that does not see to help yet...

<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

How do you deploy the app as ROOT? If you package as war file, to deploy as ROOT, change the war file to ROOT.war and have the index.html under the ROOT folder. Also check the web.xml under WEB-INF to have the welcom page set to index.html as below:

<welcome-file-list>
<welcome-file>
    index.html
</welcome-file>
</welcome-file-list>

I found the answer here - http://docs.jboss.org/resteasy/docs/3.0.2.Final/userguide/html_single/ :

"The downside of running Resteasy as a Servlet is that you cannot have static resources like .html and .jpeg files in the same path as your JAX-RS services. Resteasy allows you to run as a Filter instead. If a JAX-RS resource is not found under the URL requested, Resteasy will delegate back to the base servlet container to resolve URLs."

I created a filter instead and I was able to serve both the static page and my regular REST resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM