Create new FormFile from another Struts

I have a webpage in jsp that select a file from my computer and then save this to the database.
In the same location from the file I have the same name file but diferent extension (file.gif, file.jpg), i want save also the file with the diferent extension without have to select from the page.
It is posible.

My code in the action is

TableroForm fform = (TableroForm) form;
FotoVO fotoVO = new FotoVO();

String nombre = fform.getFoto().getFileName();
String sub = nombre.substring(nombre.lastIndexOf("."), nombre.length());

  session = request.getSession();
  context = session.getServletContext();
  String path = context.getRealPath(request.getContextPath()) + session.getId();
  path = path + "/" + nombre;

//This code to take the same file with another extension - but the filelength is 0 because the file is not found because is in another comuter....

   String archivoJPG = fform.getArchivoP().substring(0, (fform.getArchivoP().length() - 4)) + ".JPG";
   File file1 = new File(fotoVO.getZoom());
   int filelength1 = (int) file1.length();
         "Guardando el archivo " + path);
   IOUtil.saveFile(path, fform.getFoto().getFileData());

I think that I can create a new FormFile from the original or something like that but i dont know how

Can somebody help me?, its very urgent
Who is Participating?

Improve company productivity with a Business Account.Sign Up

jaggernatConnect With a Mentor Commented:
copy the file from client side to server side using this  software plexus-utils-1.3.jar [1].  

put the above jar file in web-inf/lib directory

In your java class, import FileUtils:

import org.codehaus.plexus.util.FileUtils;

//copy file from client to server using this line

FileUtils.copyDirectory(new File("c:/client/temp"), new File(" c:/server/temp"));

//  c:/client/temp  is source directory (client)
//  c:/server/temp  is destination directory (server)

>>>> diferent extension without have to select from the page.
It is posible.

I don’t think its possible.
With out selecting the file , how will you differentiate which file it is that you want to save in database?
However, How you can differentiate the names of the files is getting a substring of the file names after the “.”
so if file names are the same say for instance  file.jpg and file.gif , get the extenstions of the file names using

something like this

private String getFileName(String fileName) {
            String fileNameExtension = fileName.substring(fileName.indexOf("."),filename.length());
System.out.println(“File name extension is ” + fileNameExtension)
            return fileNameExtension;


so once you get the extension, you can decide which one you want to save in database
olgavillamizarAuthor Commented:
I want to save both in the database, but I want to have to select just one.

The problem is when I start to use my application from other computers. So the Jboss Server is on my computer. When I run my application using IE from another computer, it runs successfully. Everything correct except one thing. When I run try to upload a file, it cannot accept it and try to get the file from the server side, because the file is in the client side.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

>>>try to upload a file, it cannot accept it and try to get the file from the server side, because the file is in the client side

not really sure what you mean here. are you uploading the file from a directory  or somewhere else
olgavillamizarAuthor Commented:
im uploading the file from a directory
so what you mean when you say
cannot get the file from server side ? and
file is in the client side
why dont you upload the file in server side in that case ?
olgavillamizarAuthor Commented:
because the file is in the client side....the idea is upload to server side...

The file is in client side in c:/temp
and the app is looking in server side in c:/temp

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.