利用smartupload来下传文件,服务器端m_request.getContentLength()返回-1
利用smartupload来上传文件,服务器端m_request.getContentLength()返回-1
利用smartupload来上传文件,用户选择文件点击“上传”后,调试服务器端 m_totalBytes = m_request.getContentLength(),获取其长度为-1,不知道为什么?
客户端程序如下:
<form action="doinsert.jsp" method="get" enctype="multipart/form-data" name="form1">
.....
<tr>
<td>软件截图:</td>
<td colspan="2"><input type="file" name="file" />
<input type="submit" name="submittype" value="upload" /></td>
</tr>
doinsert.jsp如下:
<%
SmartUpload mySmartUpload=new SmartUpload();
mySmartUpload.initialize(pageContext);
//设置上载的最大值
mySmartUpload.setMaxFileSize(500 * 1024*1024);
//上载文件
mySmartUpload.upload();
%>
SmartUpload.upload()代码如下:
public void upload() throws ServletException,IOException,SmartUploadException
{
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
}
在doinsert.jsp中的上载文件时出现错误, 调试upload()里代码,发现服务器中m_totalBytes = m_request.getContentLength();这句话m_totalBytes为-1,m_request已经在前面初始化。
利用smartupload来上传文件,用户选择文件点击“上传”后,调试服务器端 m_totalBytes = m_request.getContentLength(),获取其长度为-1,不知道为什么?
客户端程序如下:
<form action="doinsert.jsp" method="get" enctype="multipart/form-data" name="form1">
.....
<tr>
<td>软件截图:</td>
<td colspan="2"><input type="file" name="file" />
<input type="submit" name="submittype" value="upload" /></td>
</tr>
doinsert.jsp如下:
<%
SmartUpload mySmartUpload=new SmartUpload();
mySmartUpload.initialize(pageContext);
//设置上载的最大值
mySmartUpload.setMaxFileSize(500 * 1024*1024);
//上载文件
mySmartUpload.upload();
%>
SmartUpload.upload()代码如下:
public void upload() throws ServletException,IOException,SmartUploadException
{
m_totalBytes = m_request.getContentLength();
m_binArray = new byte[m_totalBytes];
}
在doinsert.jsp中的上载文件时出现错误, 调试upload()里代码,发现服务器中m_totalBytes = m_request.getContentLength();这句话m_totalBytes为-1,m_request已经在前面初始化。
1 楼
lifuqiong00
2007-12-13
上网搜了一下,有筒子说是用url传值可以解决问题,不明白在哪儿用Url传值,上传文件那个按钮那儿好像无法用url传值吧,谢谢