1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
public class ProduitajtAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
ProduitajtForm aj = (ProduitajtForm) form;
FormFile myFile = aj.getFichier();
//String contentType = myFile.getContentType();
//Get the file name
String fileName = myFile.getFileName();
// byte[] fileData = myFile.getFileData();
String filePath = getServlet().getServletContext().getRealPath("/") +"upload";
/* Save file on the server */
if(!fileName.equals("")){
System.out.println("Serveur path:" +filePath);
//Create file
File fileToCreate = new File(filePath, fileName);
if(!fileToCreate.exists()){
FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);
fileOutStream.write(myFile.getFileData());
fileOutStream.flush();
fileOutStream.close();
} } |
Partager