0
내 JSP 측에서이 코드를
에 업로드 된 파일을 얻을 수 있습니다.는 어떻게 JSP 양식
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Part p1 = request.getPart("file");
InputStream is = p1.getInputStream();
Part p2 = request.getPart("photoname");
Scanner s = new Scanner(p2.getInputStream());
String filename = s.nextLine();
// get filename to use on the server
String outputfile = "C:\\Documents and Settings\\Sherman\\Desktop\\ImoveiSP\\ImoveiSP\\DB_Scripts" + filename + ".jpg";
//outputfile = outputfile + ".jpg";
//System.out.println("out = " + outputfile);
FileOutputStream os = new FileOutputStream(outputfile);
// write bytes taken from uploaded file to target file
int ch = is.read();
while (ch != -1) {
os.write(ch);
ch = is.read();
}
os.close();
out.println("<h3>File uploaded successfully! </h3>");
File file = new File("C:\\Documents and Settings\\Sherman\\Desktop\\ImoveiSP\\ImoveiSP\\DB_Scripts" + filename + ".jpg");
uploadAmazon(file, "ibagem", "");
} catch (Exception ex) {
out.println("Exception -->" + ex.getMessage());
} finally {
out.close();
}
}
이 서블릿은 업로드 된 파일을 받아 디스크에 저장 :
그리고 서블릿에서
, 나는 코드가 있습니다. 나는이 코드에 대한 두 가지 질문이: JSP 측에서
- 을 어떻게 난 단지 .JPG 또는 .MPG 파일을 전송하는 사용자를 강제 할 수 있습니까?
- jsp 쪽에서 업로드 할 입력을 하나 이상 넣으면 서블릿에서 모든 것을받는 방법은 무엇입니까?
가능한 [JSP/Servlet의 파일 업로드 방법] (http://stackoverflow.com/questions/2422468/how-to-upload-files-in-jsp-servlet/2424824#2424824) – BalusC