I have created a folder named "images" under Web Pages, which is under Oef11. Then in my servlet I am trying to tell the program to upload a file. (I am using Tomcat 5.5., commons fileUpload and commons IO from apache).
But I have a problem there. Here is a part of the code from the servlet
if (item.getContentType().equals("images/gif")) {
String fileName = item.getName();
if (fileName != null) {
fileName = FilenameUtils.getName(fileName);
}
// geüploaded file
String path2upload = this.getServletContext().getRealPath("/") + "images/" + fileName;
File uploadedFile = new File(path2upload);
request.setAttribute("filenaam",path2upload);
try {
item.write(uploadedFile);
request.setAttribute("file", fileName);
KlantDTO klant = (KlantDTO) request.getAttribute("klant");
klant.setFilename(fileName);
} catch (Exception ex) {
ex.printStackTrace();
new ServletException(ex);
ex.printStackTrace();
}
}
And here is the corresponding one from the jsp:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<img src='<c:url value="/images/${file}" /> '>
And this is what I'm getting
<img src='/Oef11/images/ '>
What I wanted to obtain was
<img src='/Oef11/images/photo.gif '>
Maybe I'm doing the getRealPath wrong...Or something else...
Can anyone please help me?