如果多次包含,JSP 会重复
假设我有一个包含数据库配置和连接的 global.jsp。
我知道这不是最好的方法,而且我不允许使用纯 jsp 之外的任何东西。问题是当这个文件被多次包含时,我会收到重新声明错误。有什么办法可以做到这一点吗?也许是 C 上的 IFDEF 之类的东西。
谢谢。
let say i have this global.jsp that include a database configuration and connection.
I know this is not the best way to do this, and I didn't allow to use anything else then a pure jsp. The problem is when is this file is included in more than once then i got re-declaration error. Is there any way to do this ? something like IFDEF on C perhaps.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查jsp包含概念这里是简单的细节和包含指令标签和包含操作标签的区别
应该使用包含指令(
<%@ include file="relativeURL" %>
):如果文件包含静态文本
如果文件很少更改(如果修改了此类包含文件,JSP 引擎可能不会重新编译 JSP)
如果您有一个可以在多个页面(例如页眉和页脚)中重复使用的通用代码片段,
则应使用
对于运行时更改的内容
选择在运行时渲染哪些内容(因为 page 和 src 属性可以采用运行时表达式)
对于经常更改的文件
,这里有链接
http://javapapers.com/jsp/difference- Between-jsp-include-directive-and-jsp-include-action/
http://www.geekinterview.com/question_details/701
http://www.daniweb.com/web-development/jsp/threads/105695
Check the jsp include concept here is the simple detail and difference of the include directive tag and include action tag
should use the include directive (
<%@ include file="relativeURL" %>
):if the file includes static text
if the file is rarely changed (the JSP engine may not recompile the JSP if this type of included file is modified)
if you have a common code snippet that you can reuse across multiple pages (e.g. headers and footers)
should use the
<jsp:include />
for content that changes at runtime
to select which content to render at runtime (because the page and src attributes can take runtime expressions)
for files that change often
here are the links
http://javapapers.com/jsp/difference-between-jsp-include-directive-and-jsp-include-action/
http://www.geekinterview.com/question_details/701
http://www.daniweb.com/web-development/jsp/threads/105695