Question

I have an ArrayList<File> object which contains files. I have set the object to a parameter titled "content" as well as a test String:

request.getSession().setAttribute("test", "test");
request.getSession().setAttribute("contents", contents);
request.getRequestDispatcher("/index.jsp").forward(request, response);

On the jsp page I am using the following to print out their values:

<table border="1" cellpadding="15px">
    <tr>
        <td>
            <b>Filename</b>
        </td>
    </tr>
    <c:forEach items="${contents}" var="currentFile">
        <tr>
            <td><c:out value="${currentFile.shortName}"/></td>
        </tr>
    </c:forEach>
</table>
<%= session.getAttribute("test") %>

However, the only thing being printed out is test even though contents definitely is populated with files.

How do I print the absolute filepaths of the File objects in the contents ArrayList on index.jsp?

Was it helpful?

Solution

You should be able to do:

<td><c:out value="${currentFile.canonicalPath}"/></td>

If contents is, indeed, a List of File.

Also, there's no specific reason to populate the Session, via the request.getSession(). You can place your data directly in to the request as an attribute using request.setAttribute(...).

For truly transient data just for the JSP, this is a better place. Putting things in the Session has scope beyond the current request. (If that's intentional, no big deal, just an FYI.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top