c:import, c:param

Hi All,

I'm trying the following:

<c:import url="header.jsp">

<c:param name="test" value="hello" />

</c:import>

and trying to output the param value in header.jsp but it displays nothing.

Help is greatly appreciated.

Thanks,

Greeshma.

[308 byte] By [Greeshma12a] at [2007-11-26 22:07:27]
# 1

stick the following line at the top of your jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

probably. it might vary a bit, depending on a few things, but read Teh Docs ™ or google "jstl tutorial" for more. or search these forums, this sort of problem arises all the time

georgemca at 2007-7-10 10:52:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

If you are unable to solve this after doing your own research...

1) Check: Is header.jsp visible to the JSP you have the c:import tag on?

2) Post the full relevant code of your current JSP which includes header.jsp and also the code for header.jsp itself.

Next time , please include as much relevant code as possible, it will reduce the time it takes for you to get a response and it will also keep the thread short.

appy77a at 2007-7-10 10:52:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thanks for your replies. I have the taglib at the top of my JSP.

I'am attaching the 2 jsp's that I'm using.

JSP that includes header.jsp:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

<html>

<body topmargin="0" leftmargin="0">

<div id="container">

<div id="header">

<c:import url="header.jsp">

<c:param name="test" value="test" />

</c:import>

</div>

</div>

</body>

</html>

and header.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

<html>

<body>

<c:out value="${test}"/>

<c:set var="hi" value="hi" />

<c:out value="${hi}" />

</body>

</html>

Only hi is displayed in the JSP.

Help is greatly appreciated.

Thanks,

Greeshma.

Greeshma12a at 2007-7-10 10:52:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

According to JSTL 1.1 Specification c:param sends an HttpRequest parameter to c:import , c:url and c:redirect.

So , in your header.jsp your code should be

<c:out value="${param.test}"/>

and not

<c:out value="${test}"/>

It is very useful to check with the JSTL spec document, when something doesn't work or simply when you want to learn more about JSTL - its a PDF document , to get the document go here:

http://jcp.org/aboutJava/communityprocess/final/jsr052/index2.html and then click on Download, and then look for this jstl-1_1-mr2-spec.pdf PDF document .

appy77a at 2007-7-10 10:52:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

> Thanks for your replies. I have the taglib at the top

> of my JSP.

> I'am attaching the 2 jsp's that I'm using.

>

> JSP that includes header.jsp:

>

> <%@ taglib uri="http://java.sun.com/jstl/core"

> prefix="c"%>

> <html>

><body topmargin="0" leftmargin="0">

><div id="container">

> <div id="header">

><c:import url="header.jsp">

><c:param name="test" value="test" />

> </c:import>

></div>

></div>

> ody>

> </html>

>

>

> and header.jsp

>

>

> <%@ taglib uri="http://java.sun.com/jstl/core"

> prefix="c"%>

> <html>

>

> <body>

> <c:out value="${test}"/>

> <c:set var="hi" value="hi" />

> <c:out value="${hi}" />

> </body>

> </html>

>

>

> Only hi is displayed in the JSP.

>

> Help is greatly appreciated.

>

> Thanks,

> Greeshma.

um, what do you expect that code to do? looks like it's working fine to me. it's done exactly what you asked

georgemca at 2007-7-10 10:52:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Thanks appy77...It works...I'll definetely check the doc's ...and I really appreciate any suggestions to improve my knowledge in jsp, java.Thanks,Greeshma...
Greeshma12a at 2007-7-10 10:52:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...