[英]How to know if a JSP file is beeing included by another one?
I have x.jsp
that can either be served as the whole response, or being included in several other jsp files. 我有
x.jsp
,可以作为整个响应,或者包含在其他几个jsp文件中。
So how can I know inside x.jsp
if it is being included by another file or not? 那么我怎么能知道
x.jsp
里面是否被其他文件包含?
You can check the value of the attribute javax.servlet.include.request_uri
in your x.jsp
page. 您可以在
x.jsp
页面中检查属性javax.servlet.include.request_uri
的值。 If set, the jsp page was included. 如果设置,则包含jsp页面。
Further details here: Java HttpServletRequest get URL in browsers URL bar 更多详细信息: Java HttpServletRequest在浏览器URL栏中获取URL
你可以在'其他文件'中有一个隐藏字段,如果你包含x.jsp
你应该为它设置一个值,当你想知道它包括你应该检查隐藏字段是否value == 'value'
时,在x.jsp
value == 'value'
。
If x.jps
have knowledge about inclusion, it means that some best practices is ignored: 如果
x.jps
有关于包含的知识,则意味着忽略了一些最佳实践:
x.jsp
is not just a view , but also some kind of controller . x.jsp
不仅仅是一个视图 ,而且还有某种控制器 。 x.jsp
to y.jsp
and z.jsp
, or introduce a variable which will contain value for appropriate case x.jsp
拆分为y.jsp
和z.jsp
,或者引入一个包含适当大小写值的变量 x.jsp
needs additional data about enviroment. x.jsp
需要有关环境的其他数据。 Of course these practices are not mandatory but you need a strong reason why you ignore them. 当然,这些做法不是强制性的,但你需要一个强有力的理由来忽略它们。
Please give us more information about your case or rephrase you question 请向我们提供有关您案件的更多信息或重新提出您的问题
Edit 编辑
My answer is abstract as your question is abstract. 我的答案是抽象的,因为你的问题是抽象的。 Get us your jsp, what should be changed and I hope you get better answer.
给我们你的jsp,应该改变什么,我希望你得到更好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.