2

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.)

4

1 回答 1

2

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?

于 2009-05-27T06:11:58.477 回答