Glassfish duplicating directory

Asked

Viewed 72 times

0

When saving a photo, instead of creating the directory ends up duplicating, apparently it puts the first directory of the Glassfish server and in the other one what I had mentioned, for being layman I am not able to identify the error, can see the error?

Error sending file: java.io.Filenotfoundexception: C: Users gfalc Appdata Roaming Netbeans 8.2 config GF_4.1.1 domain1 generated jsp Lojagames C: Users gfalc Documents Netbeansprojects Lojagames build web.... web img 2833f90d2c3fecee171be3db379b30bc.jpeg (The syntax of the file name, directory name or volume label is incorrect)

    String SAVE_DIR = "/../../web/img";//Glassfish

public String[] up(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    String[] fileName = null, tipo = null;
    try {

        String appPath = request.getServletContext().getRealPath("");


        String savePath = appPath + SAVE_DIR;


        System.out.println("Aplicativo path:" + savePath);


        File saveDir = new File(savePath);
        if (!saveDir.exists()) {
            saveDir.mkdir();
        }
        //Cria uma lista de nome de arquivos
        fileName = new String[request.getParts().size()];
        int x = 0;

        //Varre todos os campos do formulario e pega apenas os arquivos de foto
        for (Part part : request.getParts()) {
            if (part.getSubmittedFileName() != null) {
                tipo = part.getContentType().split("/");
                if (tipo[1].length() <= 4) {
                    fileName[x] = br.com.lojagames.util.Crypt.md5(part.getSubmittedFileName()) + "." + tipo[1];
                    part.write(savePath + File.separator + fileName[x]);
                    x++;
                }
            }
        }
  • What is the output of the sysout, of that impression?

  • @Jeffersonquesado Aplicativo path:C: Users gfalc Documents Netbeansprojects Lojagames build web/.. /.. /web/img

  • Well, the error message already points to the file with temporary name. On the glued exit, I saw two strange things: (a) he ignored the bars / you put; (b) he’s putting C:\\ twice, as if you were concatenating the temporary path with the save directory, not using the save directory as absolute

  • @Jeffersonquesado he ignore the bars does not bother me so much, the problem is he duplicate the C:, and I am not able to configure :(

  • I’d say your mistake is further along, but it has little to do with that. Ignoring the bars for me is a warning sign because it means ignoring your directory tree. Anyway, where he is trying to open the file to save the uploaded photo?

  • @Jeffersonquesado I put in the post following, if you can take a look thank you

  • within the if, can individually print the values of savePath, x, fileName[x]? Just before I give the part.write

  • @Jeffersonquesado pardon the delay, I am working on the project. Yes, returned me the following: Information: Application path:C: Users gfalc Documents Netbeansprojects Lojagames build web.... web img Information: Application x:0 Information: Application filename[x]:696e0e5d8ab24c4af029ac2fb5eccc6a.jpeg

  • I can’t see how he generated that strange path = Let’s hope someone more capable can help

  • 1

    @Jeffersonquesado Boy, neither did I ahuahua. I tried to give a . replace() but nothing right. Thank you so much for your time and your help.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.