Forums Register Login

jsp include and jstl questions

+Pie Number of slices to send: Send
I was trying to place a <c:out ...> inside a <jsp:include ...> command but this does not work, so I had to do the following:
<% String body = (String)request.getAttribute("body"); %>
<jsp:include page="<%=body%>" />
Infact even if I do <jsp:include page='(String)request.getAttribute("body")' /> this does not work either. The only way I could get it working was to use the above two lines.
Could someone kindly explain why this is and how I may be able to achieve what I am doing by using jsp:include and c:out
Thanks in advance.
+Pie Number of slices to send: Send
I don't believe there is any way to access request.getAttribute() values from JSTL.
Are you sure you don't actually want request.getParameter(), though?

By the way, if you really do mean getAttribute(), this single line should work:
<jsp:include page='<%= (String)request.getAttribute("body") %>' />
+Pie Number of slices to send: Send
Hi Ron,
Thanks for getting back on that. I am certain that I need request.getAttribute and I can access this using JSTL by <c ut value="${requestScope.body}" /> - but when I place this insode the <jsp:include ..> then it does not work.
Also, the one you said, i tried that many times but for some reason it won't work on my setup.
- FK
+Pie Number of slices to send: Send
Faisal, what servlet container and JSTL implementation are you using? This may help someone get to the root of your problem.
bear
+Pie Number of slices to send: Send
 

I don't believe there is any way to access request.getAttribute() values from JSTL.


Although I haven't played much with JSTL yet, I do believe that these are accessible through the requestScope collection of the expression language.
bear
+Pie Number of slices to send: Send
I am using Tomcat 4.1.24 and the latest version of jakarta-taglibs-standard.
But whats really strage is that even if I take JSTL out and try <jsp:include page='<%=(String)request.getAttribute("body")%>'/> - it does not work.
In both cases i.e. using JSTL or not I can print the value held in the request scope variable correctly (using <%=(String)request.getAttribute("body")%> or <c ut value="${requestScope.body}"/> but nothing gets displayed when using either of these inside the jsp:include.
+Pie Number of slices to send: Send
 

But whats [sic] really strage [sic] is that even if I take JSTL out and try <jsp:include page='<%=(String)request.getAttribute("body")%>'/> - it does not work.


Yes, that's really odd. I've used dynamic params to jsp:include in the past with no problems. Are you absolutely sure that the body variable is resolving to a valid context-relative URL for the include?
I'll try to give it a try on my setup later in the day.
bear
+Pie Number of slices to send: Send
Yes, definate since breaking up the statment into:
<% String body = (String)request.getAtribute("body"); %>
<jsp:include page="<%=body%>" />
works absolutely fine but this does not:
<jsp:include page='(String)request.getAtribute("body")' /> nor does
<jsp:include page='<c ut value="${requestScope.body}" />" />
Like I said when I do <c ut value="${requestScope.body}" /> in the page it correctly prints out /body/page.jsp etc
Thanks for the help but don't waste your time on it, i was juts really confused so thought I better raise the question.
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3065 times.
Similar Threads
Hibernate MVC Can't create new Client
<jsp:doBody> tag not displaying scriptlet as template text when the body content is tagdependent
Including a file dynamically
Conditional includes
include duplicate issue
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:31:17.