开发者

Using .html files as JSPs

开发者 https://www.devze.com 2023-01-26 03:58 出处:网络
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 us

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消