Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp include and jstl questions

 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to place a <cut ...> 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 cut
Thanks in advance.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic