Using .html files as JSPs

11,067

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.

Share:
11,067
jd.
Author by

jd.

Updated on July 25, 2022

Comments

  • jd.
    jd. almost 2 years

    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.
    jd. over 13 years
    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 ?
  • fasseg
    fasseg over 13 years
    yep you can add it to your web app's web.xml. you can check the servlet spec for the web application deployment descriptor jcp.org/aboutJava/communityprocess/first/jsr053/index.html
  • dutoitns
    dutoitns over 7 years
    Step (2) wasn't needed for me. I'm using Apache Tomcat 8.5.4