Mathias
Mathias

Reputation: 3981

can't get request parameter with core taglib, works with request.getparameter?

EDIT: found it at last. It doesn't work in Jetty for some reason, but worked in Tomcat when i built and ran there. No idea why though...

Oh, man i went crazy last night trying to sort this out...

simple premise:

using a Spring requestdispatcher and controller class, simple jsp page as view.

in my controller:

request.setAttribute("banana", "myValue");

if use the reqular jsp code:

<%=request.getAttribute("banana")%>

it prints as expected

but i CANT get it to work using c-taglib. I've tried everything:

<c:out value="${param.banana}"/> <c:out value="${requestScope.banana}"/> and like 4 more.

Nothing works... it just prints the value as-is i.e. ${param.banana} as text.

I have looked around but couldn't find any solution, i must be an idiot. Please help me out.

EDIT forgot to clarify: i have included the appropriate jspheader

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

also tried

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

Upvotes: 1

Views: 7711

Answers (2)

Mathias
Mathias

Reputation: 3981

For others reference:

This was an issue with the Jetty server i ran on. When deploying on Tomcat, everything worked as expected.

I'm not exactly sure what it was, i ran it as-is from within Intellj, but guess it had something to do with what libraries were deployed with the Jetty on start-up.

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691645

You probably just forgot to declare the use of the core taglib at the beginning of the JSP:

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

And the appropriate way is :

<c:out value="${requestScope.banana}"/>

or just

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

unless you have a page-scope attribute with the same name.

Upvotes: 2

Related Questions