Limiting model scope in JSP

If I put an object named "foo" into a model in a Spring controller and want to scoped it, how can I do that.

Let's say I have a page that uses a jsp tag that takes "foo" as a parameter. If I call the tag inside jsp, for example <tag foo="${bar}" />

, it seems to me that the "foo" model is interfering with the "bar".

Or even if not, if I just want to limit the scope of the "foo" model to only be available in the jsp page and not others (in the ed page or in the tag that the first jsp page calls).

+1


a source to share


1 answer


Basically, you cannot limit the scope. The only way to pass objects from controller to view is with request scope attributes.

If you have many different views / controllers for the same page, you might want to have a naming convention for your request attributes, something like the controller class name. The only problem is that access to them is not so clean.

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

      



One possible way is to use to create page scope variables:

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

      

In your example I'm not sure if I say that "foo" is interfering with the "bar", it looks like you are passing the bar to the tag as a parameter?

+1


a source







All Articles