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

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

问题描述

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

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

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

解决方案

使用2个简单步骤即可实现此目的:


  1. 为JSP servlet添加此servletmapping:

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

    这表示应用程序容器在提供html文件时使用JSP servlet。


  2. text / html < mime-mapping> c> mime type(* .html)文件,以便容器不会将HTML文件作为静态内容处理。

  3. >希望这有助于。


    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.

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

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