从定制源加载JSP页面 [英] Loading JSP pages from custom sources

查看:73
本文介绍了从定制源加载JSP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以执行JSP页面并在Web应用程序外部捕获其输出? 具体而言,在我的情况下,模式仍然存在一个普通的Web应用程序,但它不是从其类路径而是从任意源加载JSP页面.似乎我不能简单地获取RequestDispatcher并将其指向磁盘上的JSP文件.

Would it be possible to execute a JSP page and capture its output outside of a web application? Mode specifically, in my case there still exists a usual web application, but it loads JSP pages not from its classpath, but from an arbitrary source. It seems like I cannot simply get RequestDispatcher and point it to a JSP file on disk.

推荐答案

我认为使用诸如速度之类的模板引擎效果更好.这为动态内容提供了一个干净的基础结构,该基础结构与您要求的jsp/servlet内容明显不同.

I think you're better off with a templating engine like velocity. This provides a clean infrastructure for dynamic content that's clearly different from the jsp/servlet stuff that you are asking fore.

也就是说,我见过一些将jsps复制到其部署目录中的应用程序,以便容器将其拾取并翻译.如果您这样做,请注意,这会限制您将来的选择:

That said, I've seen applications that copy jsps into their deployed directory in order for the container to pick them up and translate them. Should you do this, please note that this limits your future options:

  • 您依靠自己的应用程序爆炸"-例如它不能直接用完WAR归档文件(这可能会限制您的部署选项)
  • 如果不禁用scriptlet(也可以禁用,则在运行时使jsps可编辑)可能会打开安全漏洞(但是如果禁用,则会更加困难...).禁用scriptlet会禁止jsps中包含真实的Java代码,因此,您仅限于标记库.
  • 您需要在运行时可用的Java编译器,您可能不希望在生产系统中使用它-例如,您不能在部署之前预编译jsps.另外,您在生产系统中还需要在运行时支付通常的jsp-translation-penalty.

用于禁用脚本的web.xml配置:

web.xml configuration for disabling scripting:

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <scripting-invalid>true</scripting-invalid>
    </jsp-property-group>
</jsp-config>

我希望这个web.xml代码段能够通过,预览无法正确显示...

I hope this web.xml snippet went through, the preview didn't show it correctly...

更新:试图使xml代码片段正确显示.

Update: Tried to make xml-snippet display correctly.

这篇关于从定制源加载JSP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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