日期:2014-05-19  浏览次数:20701 次

jsp上传的问题。。。求大神看看
upload.jsp

<%@ page language="java" contentType="text/html; charset=gb2312" 
  pageEncoding="gb2312" import="java.sql.*,java.util.Date,java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="mySmartUpload"
class="com.jspsmart.upload.SmartUpload" scope="page"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传处理程序</title>
</head>
<%!
  String sql;
String fileName,fileRealName,fileExt,path,pathsmall,pic_small_url,pathsmallReal;
int randomNumber=0;
long nowtime;
%>
<body>
<%
Date nowTime=new Date();
SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String addtime=matter.format(nowTime);

int count=0;
mySmartUpload.initialize(pageContext);
mySmartUpload.setTotalMaxFileSize(1024*1024);
mySmartUpload.upload();
com.jspsmart.upload.Request getRequest=mySmartUpload.getRequest();
String ni=getRequest.getParameter("e");
out.print("你好"+ni);
long picsize=0;
try{
count=mySmartUpload.getFiles().getCount();
out.println(count);
for(int i=0;i<count;i++){
com.jspsmart.upload.File file=mySmartUpload.getFiles().getFile(i);
if(file.isMissing())
continue;
randomNumber=(int)(Math.random()*100)+1;
fileRealName=mySmartUpload.getFiles().getFile(i).getFieldName();
fileExt=mySmartUpload.getFiles().getFile(i).getFileExt();
path="chapter2/upload/";
nowtime=System.currentTimeMillis();
fileName=path+nowtime+"_"+randomNumber+"."+fileExt;
mySmartUpload.getFiles().getFile(i).saveAs(fileName, mySmartUpload.getFiles().getFile(i).SAVEAS_VIRTUAL);
}
out.println("<a href=uploadform.jsp>文件上传成功<br/>文件说明:"+ni+nowtime+"<br/>继续上传</a>");
}catch(Exception e){
out.println(e.toString());
}
%>
</body>
</html>
uploadform.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
  pageEncoding="gb2312" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上传</title>
</head>
<body>
<form action="upload.jsp" method="post" enctype="mutipart/form-date" name="form" id="form">
说明:
<input type ="text" name="e" id="e" size="50"/>
<p>
文件:
<input name="file" type="file" size="60"/>
</p>
<p>
<input type="submit" name="ubmit" value="提交"/>
</p>
</form>
</body>
</html>

为什么我的值传不过。。上传也没反应。。求高手解答..是代码错了还是。。。

------解决方案--------------------
探讨
引用:
你粗心: 打错了enctype 不是mutipart/form-date 而是 mutipart/form-data

<form action="upload.jsp" method="post" enctype="mutipart/form-date" name="form" id="form">
说明:
<input type ="text" name="e……