限制 JSP 中模型的范围
如果我将一个名为“foo”的对象放入 Spring 控制器的模型中,并且想要限制其范围,我该怎么做。
假设我有一个页面,它使用一个 jsp 标记,该标记将“foo”作为参数。 如果我在jsp中调用标签,例如
,在我看来模型“foo”正在干扰“bar”。
或者即使不是,如果我只是想限制模型“foo”的范围只能在 jsp 页面中访问,而不能在其他页面中访问(在 'ed 页面中或在第一个 jsp 页面调用的标记中)。
If i put an object named "foo" into model in Spring controller, and want to limit its scope, how can I do this.
Let's say I have a page which uses a jsp tag that takes as a parameter "foo". If I call the tag inside jsp, like <tag foo="${bar}" />
, it seems to me that the model "foo" is interfering with the "bar".
Or even if not, if I just want to limit the scope of model "foo" to be accessible only in jsp page, and not in others (either in 'ed page or in a tag that first jsp page calls.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上你不能限制范围。 将对象从控制器传递到视图的唯一方法是通过请求范围属性。
如果单个页面有很多不同的视图/控制器,您可能需要为请求属性制定命名约定,例如控制器的类名。 唯一的麻烦是访问它们不是那么干净
一种可能是用于创建变量的页面范围版本:
在您的示例中,我不确定我会说“foo”正在干扰“bar”,它看起来像您是否将 bar 作为参数传递给标签?
Basically you can't restrict the scope. The only way to pass objects from a Controller to the view is via the request scope attributes.
If you have a lot of different views/controllers for a single page you may want to have a naming convention for your request attributes, something like the class name of the controller. Only trouble is that accessing them is not so clean
One possible is to use to create page scope versions of the variables:
In your example I'm not sure I'd say that 'foo' is interfering with 'bar' it looks like you are passing bar to the tag as a parameter?