aspose file tools*
The moose likes JSP and the fly likes jsp include and jstl questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp include and jstl questions" Watch "jsp include and jstl questions" New topic
Author

jsp include and jstl questions

Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
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.


The secret to creativity is knowing how to hide your sources.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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") %>' />


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
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

Joined: Jan 10, 2002
Posts: 60998
    
  65

Faisal, what servlet container and JSTL implementation are you using? This may help someone get to the root of your problem.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60998
    
  65

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

Joined: Jun 29, 2003
Posts: 285
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

Joined: Jan 10, 2002
Posts: 60998
    
  65

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

Joined: Jun 29, 2003
Posts: 285
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp include and jstl questions