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>为什么我的值传不过。。上传也没反应。。求高手解答..是代码错了还是

解决方案 »

  1.   

    你粗心: 打错了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" id="e" size="50"/>
    <p>
    文件:
    <input name="file" type="file" size="60"/>
    </p>
    <p>
    <input type="submit" name="ubmit" value="提交"/>
    </p>
    </form>
      

  2.   

    enctype="mutipart/form-date"
    这个地方写错了。应该是:
    enctype="mutipart/form-data"
      

  3.   

    不行。。就是我的说明<input type ="text" name="e" id="e" size="50"/>
    这个值。。传不到另个页面还有上传的东西。。也不显示
      

  4.   


     mutipart/form-data 是用这个类型以后 你不能通过getPrameter()去获取 跳转过来的参数了。 你需要用自己去解析 一般 用现成提供的组件去做 DiskFileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    try {
    List items = upload.parseRequest(request);
    Iterator it = items.iterator();
    while (it.hasNext()) {
    FileItem item = (FileItem) it.next();
    if (item.isFormField()) { //如果是表单域
    System.out.println("表单的参数名称:" + item.getFieldName()
    + ",对应的参数值:" + item.getString("GBK"));
    if(item.getFieldName().equals("id")){
    goodsID=item.getString();
    goodsID=ChangeEncoding.changeToGBK(goodsID);
    }
    } else { //如果是文件
    if (item.getName() != null && !item.getName().equals("")) {
    System.out.println("上传文件的大小:" + item.getSize());
    System.out.println("上传文件的类型:" + item.getContentType());
    System.out.println("上传文件的名称:" + item.getName());File file = new File(sc.getRealPath("/")
    + 保存路径, 保存文件名);
    item.write(file);

    }
      

  5.   


    为了确定你是否获取到了数据, 你可以将request.getInputStream()的数据给打出来 看就知道了