• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp include and jstl questions

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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") %>' />
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Faisal, what servlet container and JSTL implementation are you using? This may help someone get to the root of your problem.
bear
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic