9

This may be a silly question but I've found no answer when googling this.

Currently, I map the requests from someFileName.html to a servlet which then forwards to someFileName.jsp using servlet mappings in web.xml. I would like to avoid that and just configure my application server so that html files are parsed and executed as if they were JSPs (so that custom tags and EL could be used from within the HTML). Bonus to answers that allow any extensions to be mapped to the JSP processor.

I use Tomcat but I'd like the solution to be portable to other containers such as Glassfish.

jd.
  • 4,057
  • 7
  • 37
  • 45

1 Answers1

9

With 2 simple steps you can achieve this:

  1. Add this servletmapping for the JSP servlet:

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

    This tells the application container to use the the JSP servlet when serving html files.

  2. Comment out the <mime-mapping> for text/html mime type (*.html) files so that the container won't handle HTML files as static content.

Hope this helps.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
fasseg
  • 17,504
  • 8
  • 62
  • 73
  • About part 2), I may not have access to Tomcat's default web.xml to remove that. Is it possible to overwrite this value un the application's local web.xml ? – jd. Nov 22 '10 at 20:14
  • yep you can add it to your web app's web.xml. you can check the servlet spec for the web application deployment descriptor http://jcp.org/aboutJava/communityprocess/first/jsr053/index.html – fasseg Nov 22 '10 at 20:16
  • 1
    Step (2) wasn't needed for me. I'm using Apache Tomcat 8.5.4 – dutoitns Aug 20 '16 at 06:34