Save word template on server

-1

I have a problem with my application. I have a functionality that downloads a template in Word from the server, and opens it with the word, but without physically downloading it to the PC. In theory, I would have to save it in a pre-established route on the server, but when I save it, it asks for a place to save it and I can not save it on the server. Formerly if that could be done, but making several changes to the rest of the application can no longer be done. Any ideas on how to do it?

The application is a web page with Java / JSP. Greetings

PS: Like this is not the right place, but I did not know where to put the question.

public String getTemplatePath(DbCnt cnt, CTTemplate ctTemplate) throws ISPACException {
    String sName = "";


    try {
         int e = ctTemplate.getTemplate();
         Date dateTemplate = ctTemplate.getDate();

         String mimetype = ctTemplate.getMimetype();

         String ext = MimetypeMapping.getExtension(mimetype);

         sName = Integer.toString(e) + "." + ext;


         OrganizationUserInfo info = OrganizationUser.getOrganizationUserInfo();
         if(info != null) {
            String file = info.getOrganizationId();
            sName = file + "_" + sName;
         }

         File file1 = new File(this.mFileDirContext.getDocBase(), sName);

         if(file1.exists()) {

            FileResourceAttributes attributes = (FileResourceAttributes)this.mFileDirContext.getAttributes(sName);

            Date dateFile = attributes.getLastModifiedDate();


            if(dateTemplate.after(dateFile)) {

               this.bind(cnt, sName, e);


            }
         } else {
            this.bind(cnt, sName, e);

         }
    } catch (Exception arg11) {

     throw new ISPACException(arg11);
    }

    return this.mFileDirContext.getDocBase() + "/" + sName;
}

Basically what I understand what it does here is that it generates the document, with the data of the document taken from the database. Then the word is opened, but physically it is not stored in the PC, it is as if it were a temporary, not physically downloaded.

    
asked by urrutias 15.12.2017 в 10:36
source

1 answer

0

One way to get the file saved on the server you need is by using the Process class, check the java documentation .

The connection to the server is through the windows command line (CMD) .

 //conectando a un servidor remoto o servidor local 
 //esto sirve con o sin la autenticación del servidor de windows

 String commandConnect = "cmd /c net use \\" + ip
            + "\ipc$ /user:" + credentialsUserName + " " + credentialsPassword;

 //espera que el proceso finalize
 try {
        Process process = Runtime.getRuntime().exec(commandConnect);
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            throw new IOException("Command exited with " + exitCode);
        }
    } catch (Exception ex) {
        ex.getMessage();
    }

Once authenticated you should start creating your file in Word format, when you finish doing this, you should disconnect from the server, if you have to save it in a shared server.

   //Disconnect Auth
    String commandDisconnect = "cmd /c net use \\" + ip
            + "\ipc$ /d";
    Runtime.getRuntime().exec(commandDisconnect);
    //He expects the process to finalize
    try {
        Process process = Runtime.getRuntime().exec(commandDisconnect);
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            throw new IOException("Command exited with " + exitCode);
        }
    } catch (Exception ex) {
        ex.getMessage();
    }

Answer in the following Link .

Note that this is useful if you are going to connect to a remote or local server. in both ways it is possible, that way you manage the server path.

    
answered by 02.01.2018 в 22:50