日期:2014-05-18  浏览次数:20785 次

smartUpload上传文件失败,有源码!!
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>文件上传!</title>
</head>
<body>
<form action="smartuplaod_demo2.jsp" method="post" enctype="multipart/form-data">
请选择文件<input name="pic" type="file"/><br/>
名字<input type="text" name="name"/>

<input type="submit" value="上传"/>
</form>
</body>
</html>

上面是上传的jsp文件,配置后,能够正常的使用。

<%@page import="com.sun.org.apache.xalan.internal.xsltc.trax.SmartTransformerFactoryImpl"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");

com.jspsmart.upload.SmartUpload smart = new com.jspsmart.upload.SmartUpload();
smart.initialize(pageContext);
smart.upload();
com.jspsmart.upload.Files files = smart.getFiles();
System.out.println(files.getSize());
System.out.println(smart.save("upload"));

String name = smart.getRequest().getParameter("name");
System.out.println(name);
%>

<%=name %>
通过request直接获取的属性:<%=request.getParameter("name") %>
</body>
</html>

这里是接收端!
最后控制台会打印
0 0 null;
System.out.println(files.getSize());
System.out.println(smart.save("upload"));

String name = smart.getRequest().getParameter("name");
System.out.println(name);

前两者都是 0 ,后者为null。请问下是为何呢?