使用.html文件作为JSP [英] Using .html files as JSPs
问题描述
这可能是一个愚蠢的问题,但是我在Google上搜索时没有找到答案。
目前,我将来自someFileName.html的请求映射到一个servlet,然后使用web.xml中的servlet映射转发到someFileName.jsp。我想避免这种情况,只需配置我的应用程序服务器,以便解析和执行html文件,就好像它们是JSP一样(这样自定义标记和EL就可以从HTML中使用)。附加答案允许将任何扩展映射到JSP处理器。
我使用Tomcat,但我希望该解决方案可以移植到其他容器,如Glassfish。
使用2个简单步骤即可实现此目的:
-
为JSP servlet添加此servletmapping:
< servlet-mapping>
< servlet-name> jsp< / servlet-name>
< url-pattern> *。html< / url-pattern>
< / servlet-mapping>
这表示应用程序容器在提供html文件时使用JSP servlet。
-
为
text / html $ c $注释出
< mime-mapping>
c> mime type(* .html)文件,以便容器不会将HTML文件作为静态内容处理。 >希望这有助于。 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.
Comment out the
<mime-mapping>
fortext/html
mime type (*.html) files so that the container won't handle HTML files as static content.
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:
Hope this helps.
这篇关于使用.html文件作为JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!