Solved

Create new FormFile from another Struts

Posted on 2006-10-27
10
2,029 Views
Last Modified: 2012-08-13
Hi!
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();
fotoVO.setNombre(nombre);
fotoVO.setTipo(fform.getTipoF());
               
String sub = nombre.substring(nombre.lastIndexOf("."), nombre.length());

  session = request.getSession();
  context = session.getServletContext();
  String path = context.getRealPath(request.getContextPath()) + session.getId();
  IOUtil.createDirs(path);
  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";
   fotoVO.setZoom(archivoJPG);
   File file1 = new File(fotoVO.getZoom());
   int filelength1 = (int) file1.length();
               
   log.info("Guardando el archivo " + path);
   IOUtil.saveFile(path, fform.getFoto().getFileData());
   fotoVO.setPath(path);


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
0
Comment
Question by:olgavillamizar
  • 5
  • 3
10 Comments
 
LVL 10

Expert Comment

by:jaggernat
ID: 17819594
>>>> 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
0
 
LVL 1

Author Comment

by:olgavillamizar
ID: 17819658
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.
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17819952
>>>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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:olgavillamizar
ID: 17820067
im uploading the file from a directory
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17820175
so what you mean when you say
cannot get the file from server side ? and
file is in the client side
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17820197
why dont you upload the file in server side in that case ?
0
 
LVL 1

Author Comment

by:olgavillamizar
ID: 17821726
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

0
 
LVL 10

Accepted Solution

by:
jaggernat earned 500 total points
ID: 17821883
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)


[1] http://repository.codehaus.org/org/codehaus/plexus/plexus-utils/1.3/plexus-utils-1.3.jar
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jersey maven project error 7 145
attribute vs parameter and setter vs add method 17 92
Fisheye tool 2 121
login form jsp example 2 49
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question