1

I need to access file system or path a txt file of windows from solaris server. I have a deployment .war into server weblogic solaris, but I don't ability for get out txt file from server to client, in this case windows system or whatever system.

The access to txt files is from,

<input type="file" name="filename" />

enter image description here

I need read the file from client but I'm having FileNotFoundException

PLEASE HELP ME

hekomobile
  • 1,388
  • 1
  • 14
  • 35
  • You need to give us some code: both the HTML/JSP for your form and the Spring controller code that is triggered for when the form is submitted. – nickdos Sep 15 '12 at 06:40

1 Answers1

1

Your Spring MVC app running on your server does not access the original file on the client's machine (otherwise websites could do bad things to your computer) - the browser sends a copy of the file over the wire to your controller.

Here is a snippet of code I've used to copy the uploaded file to the server's file system:

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String uploadFile(
    HttpServletResponse response,
    @RequestParam(value="filename", required=true) MultipartFile multipartFile,
    Model model) throws Exception {

    if (!multipartFile.isEmpty()) {
        String originalName = multipartFile.getOriginalFilename();
        final String baseTempPath = System.getProperty("java.io.tmpdir"); // use System temp directory
        String filePath = baseTempPath + File.separator + originalName;
        File dest = new File(filePath);

        try {
            multipartFile.transferTo(dest); // save the file
        } catch (Exception e) {
            logger.error("Error reading upload: " + e.getMessage(), e);
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "File uploaded failed: " + originalName);
        }
    }
}
nickdos
  • 8,348
  • 5
  • 30
  • 47
  • Did you get a stacktrace? Do you know where the `java.io.tmpdir` is on your server file system (where the file will be saved to)? Have you run it in the debugger? – nickdos Sep 15 '12 at 06:37