I have a table in jsp with user information, where one of the columns represents user CVs:
First Name - Last Name - Cv
Tom - bla - file:///C:/CVs/Tombla.pdf
Jon - b - file:///C:/CVs/jonb.pdf
But, what happens is that both users end up showing the same pdf.
I'm trying to use the code in the following page:
[link] Displaying pdf in jsp
<table id="users" class="display" style="width:100%;">
<thead>
<tr>
<th>First Name</th>
<th>Last name</th>
<th>Cv</th>
</tr>
</thead>
<tbody>
<%
List<User> users= findUsers();
for(User user: users) {
%>
<tr>
<td><%= user.firstName() %></td>
<td><%= user.lastName() %></td>
<td>
<object data="${pageContext.request.contextPath}/cv.pdf" type="application/pdf"/><% session.setAttribute("cv", user.getCV()); %>
</td>
</tr>
<%
}
%>
</tbody>
</table>
```Webservlet
@WebServlet("/cv.pdf")
public class Cv extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
String cv = session.getAttribute("cv").toString() + ".pdf";
File file = new File(cv );
response.setHeader("Content-Type", getServletContext().getMimeType(file.getName()));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"cv.pdf\"");
Files.copy(file.toPath(), response.getOutputStream());
}
}
Both users are having the same pdf displayed.
I think this is due to the fact that the variable for the session attribute is the same, but if i create a separate variable for each table line, how can I distinguish them in the webservlet code?