jsp smartupload组件,图片上传后无法保存到指定的文件夹.

代码如下:
smartupload04.htm:
<html>
<head>
<title>smartupload</title>
</head>
<body>
<form action="smartupload04.jsp" method="post" enctype="multipart/form-data">
文件名称:<input type="text" name="uname"><br>
上传的图片:<input type="file" name="pic"><br>
<input type="submit" value="上传">
</form>
</body>
</html>
-------分割线 -------------
smartupload04.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<jsp:useBean id="smartupload" class="org.lxh.smart.SmartUpload"/>
<html>
<head>
<title>smartupload</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK") ;
smartupload.initialize(pageContext) ; // 初始化上传
smartupload.upload() ; // 准备上传
String name = smartupload.getRequest().getParameter("uname") ;
name = name + "." + smartupload.getFiles().getFile(0).getFileExt() ;
String fileName = this.getServletContext().getRealPath("/") + "upload/" + name ;
smartupload.getFiles().getFile(0).saveAs(fileName) ;
%>
<img src="upload/<%=name%>" width="300" height="200">
</body>
</html>

第1个回答  2010-06-23
要我的建议 你还是自己写一个上传功能 别用封装过的
虽然简单 但最后学不到精髓 上传是最基础的东西
等你学到了以后 估计你也不需要在百度上问这个问题了本回答被提问者采纳
第2个回答  2010-06-24
同意shengyysqa 的说法,自己写上传组件,你会比较深刻的了解到http协议,对以后都有好处。
第3个回答  2010-06-23
先以路径:this.getServletContext().getRealPath("/") + "upload/"创建一个目录,再调用saveAs
第4个回答  2010-06-23
现在是保存在哪啊?C盘根?
相似回答