[newbie] making jstl to work when jetty is run programatically

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[newbie] making jstl to work when jetty is run programatically

MMan
Hi!

I'm still experimenting and I cannot understand how to make jstl to work.

I'm using Jetty 5.1.5rc2. I'm running jetty through the following main:

    public static void main(String[] args) throws Exception
    {
        HttpServer server = new HttpServer();
        server.addListener(":8080");
       
        HttpContext context = new HttpContext();
        context.setContextPath("/");
        ServletHandler servletHandler = new ServletHandler();
        servletHandler.addServlet("jsp", "*.jsp", "org.apache.jasper.servlet.JspServlet");
        servletHandler.addServlet("Invoker", "servlet/*", "org.mortbay.jetty.servlet.Invoker");
        context.addHandler(servletHandler);
        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setDirAllowed(true);
        context.addHandler(resourceHandler);
        context.setResourceBase("./");
        server.addContext(context);
       
        server.start();
    }

I have jstl.jar and standard.jar in my WEB-INF.lib but if I invoke a jsp like the following:

<%@ page import="java.util.*" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
       prefix="c" %>
      
<%! private List list = new ArrayList(); %>
<% list.add(1); list.add(2); list.add(3); %>

<HTML>
<HEAD><TITLE>JSTL</TITLE></HEAD>
<BODY>
    <c:forEach var="item" begin="1" end="10">
        <c:out value="${item}"/>
    </c:forEach>
   
    <UL>
    <c:out value="${list.size()}"/>
    <c:forEach var="elem" items="${list}">
        <LI> <c:out value="${elem}"/> </LI>
    </c:forEach>
    </UL>
</BODY>
</HTML>

I get:
${item} ${item} ${item} ${item} ${item} ${item} ${item} ${item} ${item} ${item}
    ${list.size()}
  • ${elem}

It seems that it cannot evaluate variables in context, giving me their literals and not their actual values.

What am I doing wrong? It got to be stupid, I guess, but I wasn't able to solve it after browsing the archives, searching mortbay.org, etc.

Thanks a lot
MM