Link to home
Start Free TrialLog in
Avatar of S_B
S_B

asked on

JSP how to retrieve a return value from an include?

hi!!!

i'm including an jsp-site
with <jsp:include page="mypage.jsp" flush="true"/>

how can i get some values from this include???
that means: i'm processing something in the include and want to return it to the site where i include it...

how can i manage this, or how can i solve this problem in  different way?

i'm running jsp on tomcat 3.21

thx ahead s.

Avatar of dnoelpp
dnoelpp
Flag of Switzerland image

You can use session variables. Use this in the include JSP:

request.getSession().setAttribute("yourVariableName", yourValue);

And use this in the JSP after <jsp:include page="mypage.jsp" flush="true"/>:

yourValue = request.getSession().getAttribute("yourVariableName");

Good luck!
I think you can use:
<%@ include file=File %>  or <jsp:directive.include file=File %>

for more info check out:
http://www.jspinsider.com/reference/jsp/jspincludes.html

CJ
Dear cheeky

S_B will want to use a dynamic include (<jsp:include>), because he wants to do some processing in the page and return some results back to the calling page. So, the question is not whether to use dynamic or static includes, but how to return some values back to the calling page.
>or how can i solve this problem in  different way?

I thought implied that he might want to use a different approach.

CJ
A different approach would be to write a bean and use it in the calling page.

Instantiating the bean:

<jsp:usebean id="myName" class="YourBeanClass" />

Getting a property value from the bean and inserting it
into the text:

<jsp:getProperty name="myName" property="myValue" />

How would the included file see the bean using jsp:include? or the calling jsp see any beans used by the jsp:include file?

CJ
No, no, the bean is used instead of the included page.
OK.  Yup, that would work.

Creating convenience methods on beans (to do what your JSP include was doing) is definitely an option too.

CJ
ASKER CERTIFIED SOLUTION
Avatar of dnoelpp
dnoelpp
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of S_B
S_B

ASKER

thx a lot for the answers...
even if they don't hit my needs 100% i'm sure i can use them otherwise...

(i'm, not able to use beans because this will be processed in a different framework and a few other things which deny beans...)


lg sascha