关于jspSmartUpload的上传问题,急~~~~在线等,求求各位帮帮忙
我现在在做一个上传的应用,使用的是jspSmartUpload组件,上传的表单如text如果是中文,上传后存到数据库是乱马,我尝试了很多种转码方式结果出现的是各式各样的乱马,没法解决,只好求助于各位大哥大姐了。在线等。
环境是tomcat4.1+sql2000
//提交表单
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<div align="center">
<table width="400" border="0">
<tr>
<td><form action="upload.jsp" method="post" enctype="multipart/form-data" name="form1">
<div align="center">
<input name="path" type="hidden" id="path" value="news">
标题:<input name="title" type="text" id="title">
<input name="type" type="hidden" id="type" value="1">
<br>
文件:<input type="file" name="file">
<input type="submit" name="Submit" value="提交">
</div>
</form></td>
</tr>
</table>
</div>
</body>
</html>
\\上传页面
<link href="../css/style.css" rel="stylesheet" type="text/css"> <div align="center"></div>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page errorPage="error.jsp"%>
<%@ page import="com.jspsmart.upload.*" %>
<%@ page import="hetronic.lib.*"%>
<%@ page session="true"%><jsp:useBean id="my" scope="request" class="hetronic.lib.Upload"/>
<%! String mesg=""; %>
<%
//实例化上载bean
com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
//初始化
mySmartUpload.initialize(pageContext);
//设置上载的最大值
mySmartUpload.setMaxFileSize(50*1024*1024);
mySmartUpload.setTotalMaxFileSize(50*1024*1024);
mySmartUpload.setAllowedFilesList("pdf,PDF,rar,RAR,doc");
//上载文件
mySmartUpload.upload();
//获取表单
String path=(String)mySmartUpload.getRequest().getParameter("path");
String name=(String)mySmartUpload.getRequest().getParameter("name");
String type=(String)mySmartUpload.getRequest().getParameter("type");
String filename="";
//循环取得所有上载的文件
//取得上载的文件
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
//取得上载的文件的文件名
//取得不带后缀的文件名
//取得后缀名
String ext= mySmartUpload.getFiles().getFile(i).getFileExt();
//取得文件的大小
int fileSize=myFile.getSize();
//保存路径
String aa=getServletContext().getRealPath("/")+"file/"+path+"\\";
String trace=aa+name+i+"."+ext;
filename=filename+name+i+"."+ext+",";
//将文件保存在服务器端
myFile.saveAs(trace);
}
}
String sqlStr="insert into oyw_News(title,type,content)values(?,?,?)";
try{
PreparedStatement ptmt=LinkDataBase.getPreparedStatement(sqlStr);
ptmt.setString(1,name);
ptmt.setInt(2,Integer.parseInt(type));
ptmt.setString(3,filename);
ptmt.execute();
ptmt.close();
LinkDataBase.close();
}catch(Exception e){
}
%>