Passing variable value from one JSP to another in Spring using Tiles

1.1k views Asked by At

Spring 3.2 with Tiles 3.

I have a JSP to set a c:set var value :

<c:set var="myValue" value="abcd" />

abcd here is just for brevity, its actually being manipulated in JSP.

This JSP I have included in Tiles definition of another JSP (Demo.jsp) like :

<put-attribute name="language" value="/WEB-INF/views/web/common/myValue.jsp" />

How can I access the value of myValue variable set in first JSP in my second JSP ?

2

There are 2 answers

0
Will Keeling On

Have you tried setting the scope of the variable to request so that it is available to other pages:

<c:set var="myValue" value="abcd" scope="request" />

The risk there is that the enclosing page (Demo.jsp) might attempt to access the variable before it has been set by the nested page. It may be better to refactor your JSPs so that the setting of the variable occurs elsewhere to avoid that temporal coupling.

1
justMe On

try this:

<put-attribute name="language" value="/WEB-INF/views/web/common/${myValue}.jsp" />