Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why jsp:include parameters not visible

I have exactly the same basic question about accessing jsp:param values as this poster; following his example exactly does not work for me. The parameters passed in via jsp:include don't seem to show up in the included file. Is there something peculiar about my setup?

Caller:

<div>
    <jsp:include page="../../../common/callee.jsp">
        <jsp:param name="justinVar" value="primary" />
    </jsp:include>      
</div>

callee.jsp:

<i>method 1: [</i><b><%= request.getParameter("justinVar") %></b><i>]</i>
<p/>
<i>method 2: [</i><b>${param.justinVar}</b><i>]</i>
<p/>
<i>method 3: [</i><b>${justinVar}</b><i>]</i>
<p/>

Final output:

method 1: [null]

method 2: []

method 3: [] 

Update: The following workaround does work, it seems wrong, but perhaps the fact that it works reveals something that is not working.

<c:set var="justinVar" value="justinVARisHere" scope="request" />
<jsp:include page="../../../common/callee.jsp" />
like image 354
Justin Avatar asked Oct 12 '22 05:10

Justin


2 Answers

To nail down the problem, try to debug/explore the entire map by printing ${param} in EL or HttpServletRequest#getParameterMap() in Java code. It must give insights about what the map really contains.

like image 104
BalusC Avatar answered Oct 18 '22 03:10

BalusC


Right. I have had a similar problem that for the last hour or so and I have found a solution for my case.

I had index.jsp and tried to include news.jspf in it with text from a jsp param in the index.jsp It didn't work. It just showed the news.jspf EL as normal text.

I changed the included file name extension from .jspf to .jsp and it fixed the problem.

I'm using Eclipse, which may or may not be a factor.

Good luck

like image 37
grooble Avatar answered Oct 18 '22 01:10

grooble