Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What does getRealPath() really do?

800604Oct 27 2008 — edited Oct 27 2008
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2008
Added on Oct 27 2008
4 comments
542 views