Pergunta

In my jsp, I have the following:

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

<c:set scope="request" var="test" value="${com.xxx.foo.Bar.getBar()}" />

But this seems to store test as a string with the literal value of ${com.xxx.foo.Bar.getBar()} rather than the return value of that method (which is an enum).

Here getBar() is an instance method, not a static method.

What am I doing wrong?

Foi útil?

Solução

As suggested by others in the comments, I solved this by creating a servlet and passing in the info to the jsp, like this:

public class FooServlet extends HttpServlet
{
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException
    {
        Bar bar = new Bar();
        request.setAttribute("bar", bar.getFooBar() );
        request.getRequestDispatcher("/myPage.jsp").forward(request, response);
    }
}

In the jsp:

<%=request.getAttribute("bar") %>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top