简体   繁体   English

使用.html文件作为JSP

[英]Using .html files as JSPs

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. 目前,我将来自someFileName.html的请求映射到servlet,然后使用web.xml中的servlet映射将其转发到someFileName.jsp。 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). 我想避免这种情况,只需配置我的应用程序服务器,以便解析和执行html文件,就像它们是JSP一样(这样可以在HTML中使用自定义标记和EL)。 Bonus to answers that allow any extensions to be mapped to the JSP processor. 奖励答案,允许任何扩展映射到JSP处理器。

I use Tomcat but I'd like the solution to be portable to other containers such as Glassfish. 我使用Tomcat,但我希望该解决方案可以移植到其他容器,如Glassfish。

With 2 simple steps you can achieve this: 只需2个简单步骤即可实现:

  1. Add this servletmapping for the JSP servlet: 为JSP servlet添加此servletmapping:

     <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. 这告诉应用程序容器在提供html文件时使用JSP servlet。

  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. text/html mime类型(* .html)文件注释掉<mime-mapping> ,以便容器不会将HTML文件作为静态内容处理。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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