SmartUpload,jsp重命名上传的文件提示文件无法保存(File can't be saved (1120).)解决思路

<body>
<%
SmartUpload smart = new SmartUpload() ;
smart.initialize(pageContext) ; // 初始化上传操作
smart.upload() ; // 上传准备
String name = smart.getRequest().getParameter("uname") ;
smart.save("/upload"); // 文件保存



//IPTimeStamp its = new IPTimeStamp(request.getRemoteAddr()) ;


IPTimeStamp its = new IPTimeStamp("192.168.1.1") ;// 取得客户端的IP地址
String ext = smart.getFiles().getFile(0).getFileExt() ; // 扩展名称
String fileName = its.getIPTimeRand() + "." + ext ;
System.out.print(fileName);
      smart.getFiles().getFile(0).saveAs(this.getServletContext().getRealPath("/")+"upload"+java.io.File.separator + fileName) ;

%>
<h2>姓名:<%=name%></h2>
 <%=smart.getFiles().getFile(0).getFileName().matches("^\\w+.(jpg|gif)$")%>
<h2>姓名:<%=name%></h2>
<img src="../../../upload/<%=fileName%>">

</body>

  smart.getFiles().getFile(0).saveAs(this.getServletContext().getRealPath("/")+"upload"+java.io.File.separator + fileName) ;

改成:

 
// smart.getFiles().getFile(0).saveAs(this.getServletContext().getRealPath("/")+java.io.File.separator+"smartupload"+java.io.File.separator+"upload"+java.io.File.separator+filename);


注意:出次错误也可能是因为你的

IPTimeStamp its = new IPTimeStamp(request.getRemoteAddr()) ;// 取得客户端的IP地址

获取的客户端的IP地址格式不正确

<%@ page language="java" contentType="text/html; charset=gbk"%> <%@ page pageEncoding="gbk"%> <%@ page import="com.jspsmart.upload.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>Insert title here</title> </head> <body> <form action="upd2.jsp" method="post" enctype="multipart/form-data" name="form1"> <input type="file" name="file1"> <input type="text" name="title"> <input type="text" name="content"> <input type="submit" value="上传" > </form> </body> </html> 接受上传文件:okUpload.jsp 接受图片改变名称保存到指定目录并在网页上发布 接受参数值并显示在图片下面 <%@ page language="java" contentType="text/html; charset=gbk"%> <%@ page pageEncoding="gbk"%> <%@ page import="com.jspsmart.upload.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>上传处理</title> </head> <body> <% SmartUpload su=new SmartUpload(); //初始化 su.initialize(pageContext); //上传 su.upload(); // 设置保存信息 String dir="upload"; //获取上传文件列表集合 Files files=su.getFiles(); for(int i=0;i<files.getCount();i++){ File file=files.getFile(i); //判断上传的是不是文件 if(!file.isMissing()){ //将获取的图片另存为文件名为new,后缀名从原是文件中获得 file.saveAs(dir+"/new."+file.getFileExt(),su.SAVE_VIRTUAL); //获取图片的客户端路径名 String name1=file.getFilePathName(); out.print("客户机原始路径名: "); out.print(name1); out.print("<br>"); out.print("服务器上的相对路径名: "); //构造服务器上的相对路径名 String name2=dir+"/"+"new.jpg"; out.print(name2); out.print("<br>"); %> <!-- 将上传后的图片发布 --> <img src="<%=name2 %>"> <% } } %> <!-- 获取传过来的非文件参数值 --> <%=su.getRequest().getParameter("title") %> <br> <%=su.getRequest().getParameter("content") %> <br> <br> </body> </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值