避免为已编译的 JSP 进行数据准备
是否可以检查 JSP 是否已经编译?假设我正在做类似的事情:
read database
read an xml file
call a webservice
show data from all of above in JSP
但我不想每次都执行前三个,我想要:
if ( not already compiled JSP or data is out of date )
{
read database
read an xml file
call a webservice
}
show data in JSP
使用像 Freemarker 这样的库很容易做到这一点,但不确定缓存如何与 JSP 一起工作?
编辑:我真正要问的是JSP是否有内置缓存,以便我可以参考它,比如“10小时后重新生成JSP”,并且我可以在模型中修改某些数据时删除缓存以便重新生成 JSP。
Is it possible to check to see if a JSP has already been compiled? Let's say I'm doing something like:
read database
read an xml file
call a webservice
show data from all of above in JSP
But I don't want to do the first three every time, I want:
if ( not already compiled JSP or data is out of date )
{
read database
read an xml file
call a webservice
}
show data in JSP
This would be easy to do with a library like Freemarker but not sure how caching works with JSPs?
EDIT: What I am really asking is if JSP has a built in cache so that I can refer to it, to say something like "regenerate JSP after 10 hours" and I can, upon some data being modified in a Model, delete the cache entry so that the JSP is regenerated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jsp 是否编译与是否适合读取数据库、读取 xml 文件或调用 Web 服务无关。
编译与执行完全分开。这些决定在执行时是适当的。
运行 Web 应用程序的 Web 容器可以检测 jsp 是否已编译,如果源比编译版本更新,则重新编译它。但具体如何完成取决于容器,并且这在代码本身中并不容易完成。
除非 JSP 本身发生更改,并且容器检测到这种需要,否则不需要重新编译 JSP。我不知道有哪一个有预定再生机制。
从您的编辑看来,您实际关心的可能是数据缓存,它不会自动提供,但可以通过包含类似 ehcache< /a>.
Whether the jsp is compiled has no bearing on whether it's appropriate to read a database, read an xml file or call a webservice.
Compilation is completely separate from execution. These decisions are appropriate at execution.
The web container running your web application can detect whether a jsp has been compiled, and recompile it if the source is more current than the compiled version. But exactly how that's done depends on the container, and it is not something easily done in the code itself.
There's no need to recompile the JSP unless the JSP itself changes, and containers detect this need. I'm not aware of any that have a mechanism for scheduled regeneration.
From your edit it sounds like your actual concern might be data caching, which is not supplied automatically, but can be enabled by including something like ehcache.