真是搞笑,这的声势浩大的AppServer竟然连传个文件都不行.
全部是服务器运行中的乱七八糟的东东。(就是传完文件,竟然发现都是以前一些请求的内容�
http://www.knowledgelab.net/cgi-bin/bbs/viewthread.php?tid=1381
你不加把劲,看他还有什么办法?
try{//获得提交数据�
data = req.getInputStream();
size = req.getContentLength();
in = new BufferedInputStream(data,size);
}catch(Exception e1){}
b=new byte[size];
for(i =0;i<size;i++){
b[i] = 0;
}
i = 0;
try{
int j = 0;
while (true){
j = in.read(b,i,size);
i = i + j;
if (i >= size){break;}
}
in.close();
}catch(Exception e3){//经常抛出数组越界的异�
}
发生异常时req.getContentLength()返回的数值笔上传文件的大小还小!接着在循环读入输入内容时in.read(b,i,size)就抛出了一个数组越界的异常�
1.Introduction
This is a sample that uploads text or image files from the browser to the web server.
When IBM's ISVs use WebSphere Application Server,they have the requirement to
upload text or image files from the browser to the server.
On IBM platform, the recommended approach is to write a servlet.
It is understood that a form using "multipart/form-data" can transmit the file
content in the form back to the server. The servlet can then parse the parameters
from the form and save the embedded file on the server.
This document describes how to use the servlet.
2.Source file
(1).IRNewItemServlet.java
(2).IRMultiDataFormParser.java
(3).IRException.java
3.Test Environment
(1).Windows NT Server 4.0
(2).Netscape Communication Browser 4.0 and Microsoft IE 4.0
(3).IBM WebSphere
4.Usage
(1) Complile three java source files to generate three class files
(2) Put these three class files into WebSphere's servlets directory
(3) Put the sample html file UploadServletForm.html into the document directory of WebServer
(4) Invoke these servlets via URL UploadServletForm.html
5.Browser End Behavior
The server should serve up a form that enables the browser user to select
one file from the local file system (local to the browser).
The form must contain the following fields:
- source file: the fullpath name of the source file;
- target filename: the name this file will be stored as on the server side.
This field should be initialized to the name of the selected file, but the user
can over-write this to a different name.
- replace or not: this is a boolean field which the user is to fill in yes or no.
The form must contain the following buttons:
- a "browse" button which allows the user to select a file,
- an "upload" button to indicate that the selection is complete and file upload
can begin.
When the "browse" button is pressed, the local file system should be
displayed, probably as in windows explorer. When the user selects a file,
the full pathname of the selected file is filled into the source file field
in the form.
The user can type over the target filename and target directory pathname
before pressing the "upload" button. When the "upload" button is pressed,
the form (with the appropriate parameters and file content) is sent back to the server.
Presumably the selected file (pathname as well as file content) is
sent back to the server with the form. If the server fails to store the file
successfully, appropriate error messages should be displayed in the browser.
Possible error messages are:
- "file data corrupted",
- "file system is full",
- "error saving file",
- "target file already exists and user elects not to replace it", etc.
If the file is saved successfully, a message should be displayed at
the browser to indicate success.
6.Server Behavior
When the form response is received, the server should
- parse the returned form for the parameters related to the file, and
- store the file data in the server's file system using the directory and
file names returned with the form. If the directory or the file name doesn't
exist yet, it is created. If the file already exists, the file is replaced
if the user so indicated. Otherwise an error is returned.
The server assumes a default directory under which the file is stored (in the sample,
the directory is c:\temp.)The file name is the same as the source file (passed back
to the server as a parameter).
The server then sends a message to the client indicating the status
(success or failure, and error code if failure) of the file upload. The
application can terminate after sending the message, or wait until invoked again.
7.Design Considerations
This sample program is defined to demonstrate how to implement the file
upload functionality using IBM's WebSphere, and to provide re-useable code for
ISVs who need this function. For the latter reason, the design should provide
the appropriate interface so an ISV application can easily integrate with it.
The file to be up-loaded can be either text or image.
One can upload a file using <INPUT TYPE="file"> within a FORM tag. This will
allow you to select files through browse button.To upload more than one file
it needs to define multiple <INPUT TYPE="file"> tags as it is not possible to
choose multiple files through a single INPUT tag.
这是jingmc的答复,按照他的答复,我的问题解决了,跟楼主所说的问题一样�
用上9080就好多了�
而且我存超长字符串时用到流存储时也出现这个情况,怀疑websphere环境下对流的操作有问题!