jspsmartupload上传图片时,文件名为中文解决了,但是还是上传不了图片,也没有抛异常,就是文件名为中文
1个回答
展开全部
jspSmartUpload 是由www.jspsmart.com 网站开发的一个可免费使用的全功能的文件上传下载组件,适于嵌入执行上传下载操作的JSP 文件中。jspSmartUpload的默认编码方式是GBK,因此只有使用GBK编码时中文能正常显示,有可能是你的jspSmartUpload源程序有问题,我这里有个例子,当时测试通过了,你可以参考一下:
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gbk" pageEncoding="gbk"%>
<%@ page import="com.jspsmart.upload.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP</title>
</head>
<body>
<center>
正在上传……
<%
try
{
request.setCharacterEncoding("GBK");
SmartUpload su=new SmartUpload();
su.initialize(pageContext);
su.service(request,response);
su.upload();
int count=su.save("/upload");
out.println(count+"个文件上传成功<br>");
for(int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file=su.getFiles().getFile(i);
if(file.isMissing())
continue;
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>"+ file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" +file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>"+ file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>"+ file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>"+ file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR>");
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<a href="fileupload.jsp">重新上传</a>
</center>
</body>
</html>
上传的页面
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gbk" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
文件上传实例</title>
</head>
<body>
<p align="center">上传文件选择</p>
<FORM METHOD="POST" ACTION="upload.jsp"
ENCTYPE="multipart/form-data">
<input type="hidden" name="TEST" value="good">
<table width="75%" border="1" align="center">
<tr>
<td><div align="center">1、
<input type="FILE" name="FILE1" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">2、
<input type="FILE" name="FILE2" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">3、
<input type="FILE" name="FILE3" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">4、
<input type="FILE" name="FILE4" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="上传它!">
</div></td>
</tr>
</table>
</FORM>
</body>
</html>
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gbk" pageEncoding="gbk"%>
<%@ page import="com.jspsmart.upload.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP</title>
</head>
<body>
<center>
正在上传……
<%
try
{
request.setCharacterEncoding("GBK");
SmartUpload su=new SmartUpload();
su.initialize(pageContext);
su.service(request,response);
su.upload();
int count=su.save("/upload");
out.println(count+"个文件上传成功<br>");
for(int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file=su.getFiles().getFile(i);
if(file.isMissing())
continue;
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>"+ file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" +file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>"+ file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>"+ file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>"+ file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR>");
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<a href="fileupload.jsp">重新上传</a>
</center>
</body>
</html>
上传的页面
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gbk" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
文件上传实例</title>
</head>
<body>
<p align="center">上传文件选择</p>
<FORM METHOD="POST" ACTION="upload.jsp"
ENCTYPE="multipart/form-data">
<input type="hidden" name="TEST" value="good">
<table width="75%" border="1" align="center">
<tr>
<td><div align="center">1、
<input type="FILE" name="FILE1" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">2、
<input type="FILE" name="FILE2" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">3、
<input type="FILE" name="FILE3" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">4、
<input type="FILE" name="FILE4" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="上传它!">
</div></td>
</tr>
</table>
</FORM>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询