0
어떤 유형의 파일 (한 번에 하나의 파일)을 업로드하고 싶지만 내 ** HTML 양식이 경로가 아닌 소스 파일 이름 만 반환하는 문제에 직면하고 있습니다. 내 html 파일 : 업로드 할 파일을 선택합니다 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);
%>
이 코드는 유령처럼 보입니다. 파일 업로드에 대해 살펴 보셨습니까? –
관련 항목 : http://stackoverflow.com/questions/81180/how-to-get-the-file-path-from-html-input-form-in-firefox-3/3374408#3374408 – BalusC