jstl problem : 2 last scriptlet to remove from my jsp

I use a code that works fine but here's the last scriptlets in my jsp :

<%  List listMillesime= MultiMillesimeFactory.getInstance().getListMillesimeActif();
    pageContext.setAttribute("listMillesime",listMillesime);
    %>
...
<c:forEach var="millesime" items="${listMillesime}">
...
</c:forEach>

Here is the factory declaration :

public class MultiMillesimeFactory {

    private static MultiMillesime multiMillesime;

    private MultiMillesimeFactory(){
    }

    public static MultiMillesime getInstance() {
        if (multiMillesime == null) {
            multiMillesime = new MultiMillesime();
        }
        return multiMillesime;
    }
}

Multimillesime is a standard class with a method getListMillesimeActif returning a list. Declaration :

public class MultiMillesime {
...
   public List getListMillesimeActif() throws Exception {
     List _l = Collections.synchronizedList(new LinkedList());
...
     return _l;
   }
}

c:for each works fine on list and enum but here the problem comes from the use of the getInstance, I've tried MultiMillesimeFactory.Instance.ListMillesimeActif without success.

And the last scriptlet is :

<a href='<%=request.getContextPath() %>

I'm not sure that both of these are removable.

Answers


You can replace the <%=request.getContextPath() %> scriptlet with a JSTL tag:

<a href="${pageContext.request.contextPath}" />

It is not uncommon to see something like this, either:

<c:set var="ctx" value="${pageContext.request.contextPath}"/>
...
<a href="${ctx}" />

As for the issue with the MultiMillesimeFactory: it looks like that's a class in your codebase, and we can't magically debug that issue for you. It doesn't sound like a JSP problem.

What does "tried MultiMillesimeFactory.Instance.ListMillesimeActif without success" mean?


Edit: re: your comment: I'm not sure I understand what you mean, but I'd guess the problem is that you need to use the fully qualified class name of MultiMillesimeFactory to look it up properly. However, you really should avoid using scriptlets as much as possible. Instead, use a proper servlet to inject the ListMillesimeActif into the request, like this:

public class MyServlet extends HttpServlet implements Servlet
{
    //...

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    {
        //...
        List listMillesime = MultiMillesimeFactory.getInstance().getListMillesimeActif();
        request.setAttribute("millesime", listMillesime);
        //...
    }

    //...
}

Need Your Help

WPF - MVVM Viewmodel setup

c# wpf mvvm viewmodel

I'm having some issues with the setup i'm currently using with my mvvm application. Having seen some posts on here, i get the feeling i may be doing this slightly wrong.

Web automation using PHP/cURL

php curl scripting

I want to access to the several pages of this list. My try is the code below with which I'm getting an xml file with the data of the hotels of the first page, but I want to access to the pages wher...