jspsmartupload 的上传问题 文件无法保存
请帮我看看这段代码<%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql...
请帮我看看这段代码
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@include file ="ChkPwd.jsp"%>
<%@ page import='java.util.*'%>
<%@ page import='java.text.*'%>
<%@ page import="com.smart.upload.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="msks.*"%>
<jsp:useBean id="ConnectData" scope="page" class="msks.ConnectData" />
<jsp:useBean scope="page" id="Paper" class="msks.Paper" />
</head>
<BODY>
<% SmartUpload mySmartUpload = new SmartUpload();//新建一个SmartUpload对象
final String UpFileType="pdf";
final int MaxFileSize=10240000;
String ErrMsg=null; //错误信息
boolean ERR=false; //错误标志
//上传初始化
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
nt count = mySmartUpload.save("./paperdatabase");// 将上传文件全部保存到指定目录 /*TOMCAT测试这里有错误*/
out.println(count+"个文件上传成功!<br>");
//获取论文信息
String paperTitle=mySmartUpload.getRequest().getParameter("paperTitle");
String paperAuthor=mySmartUpload.getRequest().getParameter("paperAuthor");
String authorEmail=mySmartUpload.getRequest().getParameter("authorEmail");
// 取当前文件
com.smart.upload.SmartFile myFile = mySmartUpload.getFiles().getFile(0);
// 取得文件并保存
if (!myFile.isMissing())
{
//得到文件扩展名
String FileType=myFile.getFileExt();
out.println(myFile.getFileName());
FileType=FileType.toLowerCase(); //将扩展名转换成小写
if (UpFileType.indexOf(FileType)==-1)
{
ERR=true;
ErrMsg="上传文件失败!目前只允许上传以下格式的文件:"+UpFileType;
}
//得到文件大小
int FileSize=myFile.getSize();
if (ERR==false&&FileSize>MaxFileSize)
{
ERR=true;
ErrMsg="上传文件失败!文件大小超出了限定的范围(最大"+MaxFileSize/1024+"K)";
}
if(ERR==false)
{
long paperNo=0;
Connection dbConn= ConnectData.getConn();
Statement stmt_add=dbConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from paper order by paperNo desc";
ResultSet rsPaper = stmt_add.executeQuery(sql);
rsPaper.first();
paperNo=(rsPaper.getLong("paperNo"));
paperNo++;
String paperUrl=paperNo+"."+FileType;
myFile.saveAs("/paperdatabase/" + paperUrl, mySmartUpload.SAVE_VIRTUAL);
//将论文信息保存到数据库中
int paperAdd= stmt_add.executeUpdate(sqlInsertPaper);
if (paperAdd > 0)
{
out.println("<p><font color=blue>添加论文信息成功</font></p>");
out.println("<div><input type=button Subject=btn value=\"继续添加\" onClick='window.location=\"./paper_add.jsp\"'></div>");
}
else
{
out.println("<p><font color=red>添加论文信息失败,请重试</font></p>");
out.println("<div><input type=button Subject=btn value=\"返回\" onClick='window.history.go(-1)'></div>");
return;
}
}
else
{
out.print ("<script>alert('"+ErrMsg+"');</script>");
}
} %>
帮忙解决啊。。。
只有14分,悬赏10分。。。 展开
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@include file ="ChkPwd.jsp"%>
<%@ page import='java.util.*'%>
<%@ page import='java.text.*'%>
<%@ page import="com.smart.upload.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="msks.*"%>
<jsp:useBean id="ConnectData" scope="page" class="msks.ConnectData" />
<jsp:useBean scope="page" id="Paper" class="msks.Paper" />
</head>
<BODY>
<% SmartUpload mySmartUpload = new SmartUpload();//新建一个SmartUpload对象
final String UpFileType="pdf";
final int MaxFileSize=10240000;
String ErrMsg=null; //错误信息
boolean ERR=false; //错误标志
//上传初始化
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
nt count = mySmartUpload.save("./paperdatabase");// 将上传文件全部保存到指定目录 /*TOMCAT测试这里有错误*/
out.println(count+"个文件上传成功!<br>");
//获取论文信息
String paperTitle=mySmartUpload.getRequest().getParameter("paperTitle");
String paperAuthor=mySmartUpload.getRequest().getParameter("paperAuthor");
String authorEmail=mySmartUpload.getRequest().getParameter("authorEmail");
// 取当前文件
com.smart.upload.SmartFile myFile = mySmartUpload.getFiles().getFile(0);
// 取得文件并保存
if (!myFile.isMissing())
{
//得到文件扩展名
String FileType=myFile.getFileExt();
out.println(myFile.getFileName());
FileType=FileType.toLowerCase(); //将扩展名转换成小写
if (UpFileType.indexOf(FileType)==-1)
{
ERR=true;
ErrMsg="上传文件失败!目前只允许上传以下格式的文件:"+UpFileType;
}
//得到文件大小
int FileSize=myFile.getSize();
if (ERR==false&&FileSize>MaxFileSize)
{
ERR=true;
ErrMsg="上传文件失败!文件大小超出了限定的范围(最大"+MaxFileSize/1024+"K)";
}
if(ERR==false)
{
long paperNo=0;
Connection dbConn= ConnectData.getConn();
Statement stmt_add=dbConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from paper order by paperNo desc";
ResultSet rsPaper = stmt_add.executeQuery(sql);
rsPaper.first();
paperNo=(rsPaper.getLong("paperNo"));
paperNo++;
String paperUrl=paperNo+"."+FileType;
myFile.saveAs("/paperdatabase/" + paperUrl, mySmartUpload.SAVE_VIRTUAL);
//将论文信息保存到数据库中
int paperAdd= stmt_add.executeUpdate(sqlInsertPaper);
if (paperAdd > 0)
{
out.println("<p><font color=blue>添加论文信息成功</font></p>");
out.println("<div><input type=button Subject=btn value=\"继续添加\" onClick='window.location=\"./paper_add.jsp\"'></div>");
}
else
{
out.println("<p><font color=red>添加论文信息失败,请重试</font></p>");
out.println("<div><input type=button Subject=btn value=\"返回\" onClick='window.history.go(-1)'></div>");
return;
}
}
else
{
out.print ("<script>alert('"+ErrMsg+"');</script>");
}
} %>
帮忙解决啊。。。
只有14分,悬赏10分。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询