0

I'm using tomcat 8 and uploading image to server by this code:

public static String uploadImage(String description, HttpServletRequest request) throws ServletException {
        Part filePart;
        try {
            filePart = request.getPart(PARAM_NAME_IMAGE);
            try(OutputStream out = new FileOutputStream(new File(PATH + description + ".jpg"));
                InputStream fileContent = filePart.getInputStream()){
                int read;
                byte[] bytes = new byte[1024];
                while ((read = fileContent.read(bytes)) != -1) {
                    out.write(bytes, 0, read);
                }
            }
        } catch (IOException e) {
            LOG.error("IOException", e);
        }
        return PATH_TO_IMAGE + description + ".jpg";
    }

Then i save image path to DB for my item. And then i want to see it on the page by using:

<img src="${item.imagePath}" width="350" height="320" />

But here is what I see

And then if I restart server everything is ok and its shown

So, I need to see what I upload without restarting server

1 Answers1

-1

Is your HTTP WEB Server and your Java Server container (Servlet or Enterprise container) configured that your request is a Multipart Request? multipart/form-data specification (RFC-2388). I would iterate through the form-data after getParts on the Request.

Gabor Jakab
  • 236
  • 2
  • 6