powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / HttpClient & fileupload
1 сообщений из 1, страница 1 из 1
HttpClient & fileupload
    #33431241
kamolsan
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Здравствуйте!!!

Ситуация:
Надо отправить файлы на сервер с помощью HttpClient (org.apache.commons.httpclient) и FileUpload (org.apache.commons.fileupload)

Взял пример из интернета.

ProcessFileUpload.jsp
Код: plaintext
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.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page  import ="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page  import ="org.apache.commons.fileupload.FileItem"%>
<%@ page  import ="java.util.List"%>
<%@ page  import ="java.util.Iterator"%>
<%@ page  import ="java.io.File"%>
html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Process File Upload</title>
</head>
<%
        System.out.println("Content Type ="+request.getContentType());

        DiskFileUpload fu =  new  DiskFileUpload();
        // If file size exceeds, a FileUploadException will be thrown
        fu.setSizeMax( 1000000 );

        List fileItems = fu.parseRequest(request);
        Iterator itr = fileItems.iterator();

         while (itr.hasNext()) {
          FileItem fi = (FileItem)itr.next();

          //Check if not form field so as to only handle the file inputs
          //else condition handles the submit button input
           if (!fi.isFormField()) {
            System.out.println("\nNAME: "+fi.getName());
            System.out.println("SIZE: "+fi.getSize());
            //System.out.println(fi.getOutputStream().toString());
            File fNew=  new  File(application.getRealPath("/"), fi.getName());

            System.out.println(fNew.getAbsolutePath());
            fi.write(fNew);
          }
           else  {
            System.out.println("Field ="+fi.getFieldName());
          }
        }
%>
<body>
Upload Successful!!
</body>
</html>

а вот форма UploadFiles.html

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
<HTML>
  <HEAD>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"/>
    <TITLE>File Upload Page</TITLE>
  </HEAD>
  <BODY>Upload Files
    <FORM name="filesForm" action="ProcessFileUpload.jsp"
    method="post" enctype="multipart/form-data">
        File  1 :<input type="file" name="file1"/><br/>
        File  2 :<input type="file" name="file2"/><br/>
        File  3 :<input type="file" name="file3"/><br/>
        <input type="submit" name="Submit" value="Upload Files"/>
    </FORM>
  </BODY>
</HTML>

Выдаёт ошибку:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
HTTP Status  500  - type Exception reportmessage description 
The server encountered an internal error () that prevented it from fulfilling  this  request.exception org.apache.jasper.JasperException: javax/servlet/ServletInputStream
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java: 254 )
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 295 )
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java: 241 )
 at javax.servlet.http.HttpServlet.service(HttpServlet.java: 853 )
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 247 )
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 193 )
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 256 )
...
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java: 584 )
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java: 683 )
 at java.lang.Thread.run(Thread.java: 534 )
Apache Tomcat/ 4 . 1 . 30 

...

Вопрос: В чем ошибка?

Заранее спасибо!!!
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / HttpClient & fileupload
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]