Je veux télécharger n'importe quel type de fichier (un fichier à la fois), mais je suis confronté au problème mon formulaire ** html ne renvoie que le nom de fichier source pas le chemin. mon fichier html: Sélectionnez un fichier à télécharger: Télécharger le fichier dans jsp
FileUpload.jsp :-
<%@ page import="java.util.*,java.io.*"%>
<%
String path=request.getParameter("filename");
System.out.println(path);
String newPath="";
int count=0;
if(path!=null)
{
String arr[]=new String[100];
StringTokenizer st=new StringTokenizer(path,"/");
while(st.hasMoreTokens())
{
arr[count]=st.nextToken();
count++;
}
// create ur own path
newPath="/home/saurabh/"+arr[count-1];
int c;
try{
FileInputStream fis=new FileInputStream(path);
FileOutputStream fos=new FileOutputStream(newPath);
while((c=fis.read())!=-1)
{
fos.write((char)c);
}
}
catch(Exception e){e.printStackTrace();}
}
out.println("Thanks for using");
out.println("<br>");
out.println("<br>");
out.println("1.File1 Uploaded from :: "+path);
out.println("<br>");
out.println("<br>");
out.println("2.Uploaded File1 is Saved in :: "+newPath);
%>
Ce code a l'air effrayant, avez-vous jeté un oeil sur les communs fileupload? –
Connexe: http://stackoverflow.com/questions/81180/how-to-get-the-file-path-from-html-input-form-in-firefox-3/3374408#3374408 – BalusC