使用 .html 文件作为 JSP [英] Using .html files as JSPs

查看:13
本文介绍了使用 .html 文件作为 JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我在谷歌搜索时没有找到答案.

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

目前,我将来自 someFileName.html 的请求映射到一个 servlet,然后使用 web.xml 中的 servlet 映射转发到 someFileName.jsp.我想避免这种情况,只配置我的应用程序服务器,以便像 JSP 一样解析和执行 html 文件(以便可以在 HTML 中使用自定义标记和 EL).对允许将任何扩展映射到 JSP 处理器的答案的奖励.

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.

我使用 Tomcat,但我希望该解决方案可移植到其他容器,例如 Glassfish.

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

推荐答案

通过 2 个简单的步骤,您可以实现:

With 2 simple steps you can achieve this:

  1. 为 JSP servlet 添加这个 servletmapping:

  1. Add this servletmapping for the JSP servlet:

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

这告诉应用程序容器在提供 html 文件时使用 JSP servlet.

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

text/html mime 类型 (*.html) 文件注释掉 以便容器不会处理 HTML文件作为静态内容.

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

希望这会有所帮助.

这篇关于使用 .html 文件作为 JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆