Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Root context mapping problem

 
Mark Fraser
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm mapping a servlet to the root of the server. The servlet runs fine but the linked CSS, scripts and images are returned containing the HTML of the page that linked to them instead. I've done many servlets but have seen nothing like this. Is this a specific problem with mapping to the root?

Here's my mapping:
<!-- Home Servlet -->
<servlet>
<servlet-name>HomeServlet</servlet-name>
<servlet-class>com.companyname.inet.servlet.home.HomeServlet</servlet-class>
<init-param>
<param-name>jspRoot</param-name>
<param-value>/WEB-INF/jsp/home/</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HomeServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- /Home Servlet -->

Thanks for any help you can provide.
 
Mark Fraser
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found my own answer. Sorry for the distraction.
Here's what I had to do:
<!-- Home Servlet -->
<servlet>
<servlet-name>HomeServlet</servlet-name>
<servlet-class>com.companyname.inet.servlet.home.HomeServlet</servlet-class>
<init-param>
<param-name>jspRoot</param-name>
<param-value>/WEB-INF/jsp/home/</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HomeServlet</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<!-- /Home Servlet -->

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

The welcome-file-list entry isn't necessary since it's the defined default in the Tomcat /conf/web.xml, but it illustrates the solution better.
I hope this helps someone else.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic