限制 JSP 中模型的范围

发布于 2024-07-23 07:56:15 字数 273 浏览 5 评论 0原文

如果我将一个名为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生一个溪 2024-07-30 07:56:15

基本上你不能限制范围。 将对象从控制器传递到视图的唯一方法是通过请求范围属性。

如果单个页面有很多不同的视图/控制器,您可能需要为请求属性制定命名约定,例如控制器的类名。 唯一的麻烦是访问它们不是那么干净

${requestScope['com.your.app.Controller.RESULT']}

一种可能是用于创建变量的页面范围版本:

<c:set var='result' value="${requestScope['com.your.app.Controller.RESULT']}"/>
...
${result}

在您的示例中,我不确定我会说“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

${requestScope['com.your.app.Controller.RESULT']}

One possible is to use to create page scope versions of the variables:

<c:set var='result' value="${requestScope['com.your.app.Controller.RESULT']}"/>
...
${result}

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文