没有文档,有例程可以吗
<%@ page contentType='text/html; charset=GBK' %>
<jsp:useBean id="connAdmin" scope="page" class="com.mms.dbConnAdmin" />
<jsp:useBean id="magaitem" scope="page" class="com.mmsExt.MagaItem" />
<%@ page import="com.jspsmart.upload.*" %>
<%@ page import='com.mms.*' %>
<%@ page import='java.util.*' %>
<%@include file="common/prom.jsp"%><link rel="stylesheet" href="images/cp.css" type="text/css">
<%
DefaultSet ds = new DefaultSet();
togb2312 to = new togb2312();
com.mms.util ut = new com.mms.util();//实例化上载bean
com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
mySmartUpload.initialize(pageContext);
//初始化
//设置上载的最大值
mySmartUpload.setMaxFileSize(500 * 1024*1024);
//上载文件
mySmartUpload.upload();
//com.jspsmart.upload.Request myRequest=new com.jspsmart.upload.Request();
//循环取得所有上载的文件
int imgNum = mySmartUpload.getFiles().getCount();
String type = mySmartUpload.getRequest().getParameter("type");
String magaid = mySmartUpload.getRequest().getParameter("magazineid");
String zj = mySmartUpload.getRequest().getParameter("zj");
String bm = mySmartUpload.getRequest().getParameter("bm");
String nr = mySmartUpload.getRequest().getParameter("content");
String fssj_yy = mySmartUpload.getRequest().getParameter("fssj_yy");
String fssj_mm = mySmartUpload.getRequest().getParameter("fssj_mm");
String fssj_dd = mySmartUpload.getRequest().getParameter("fssj_dd");
String fssj_s = mySmartUpload.getRequest().getParameter("fssj_s");
String fssj_f = mySmartUpload.getRequest().getParameter("fssj_f");
String fssj_m = mySmartUpload.getRequest().getParameter("fssj_m");
String sendtime = fssj_yy+","+fssj_mm+","+fssj_dd+","+fssj_s+","+fssj_f+","+fssj_m;
String ext = "";
String texturl = "";
String imgurl = "";
String bellurl = "";
//取得上载的文件
for (int i=0;i<imgNum;i++){
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
//取得上载的文件的文件名
String myFileName=myFile.getFileName();
//取得不带后缀的文件名
String suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
//取得后缀名
ext= mySmartUpload.getFiles().getFile(i).getFileExt();
//取得文件的大小
int fileSize=myFile.getSize()/1000;
//保存路径
//将文件保存在服务器端
String trace = ds.get("Wset")+"/source/img/maga/"+bm+"_"+zj+"."+ext;
myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
//下面的是将上载的文件保存到数据库中
//将文件读到流中
java.io.File file = new java.io.File(trace);
java.io.FileInputStream fis = new java.io.FileInputStream(file);
if(i==0)
imgurl = bm+"_"+zj+"."+ext;
else
bellurl = bm+"_"+zj+"."+ext;
}
}
outFile of = new outFile("",ds.get("Wset")+"/source/img/maga/",bm+"_"+zj+".txt");
of.makeTxtFile(to.getStr(nr),bm+"_"+zj+".txt");
texturl = bm+"_"+zj+".txt";
//将数据存入数据库
magaitem.save(magaid,texturl,bellurl,imgurl,sendtime);
%>
<form action=addmagaitem.jsp name="addform" method=post>
<input type="hidden" name="type" value="<%=type%>">
<input type="hidden" name="magazineid" value="<%=magaid%>">
<input type="hidden" name="zj" value="<%=Integer.parseInt(zj)+1%>">小说当前章节添加成功,是否添加该小说的下一章内容? <input class="bginput" type="submit" name="submit" value=" 确定 " >
<input class="bginput" type="button" name="" value=" 返回 " onclick="document.location.href='editmaga.jsp?type=<%=type%>'" > </form>
</form>
</body>
<%@ page contentType='text/html; charset=GBK' %>
<jsp:useBean id="connAdmin" scope="page" class="com.mms.dbConnAdmin" />
<jsp:useBean id="magaitem" scope="page" class="com.mmsExt.MagaItem" />
<%@ page import="com.jspsmart.upload.*" %>
<%@ page import='com.mms.*' %>
<%@ page import='java.util.*' %>
<%@include file="common/prom.jsp"%><link rel="stylesheet" href="images/cp.css" type="text/css">
<%
DefaultSet ds = new DefaultSet();
togb2312 to = new togb2312();
com.mms.util ut = new com.mms.util();//实例化上载bean
com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
mySmartUpload.initialize(pageContext);
//初始化
//设置上载的最大值
mySmartUpload.setMaxFileSize(500 * 1024*1024);
//上载文件
mySmartUpload.upload();
//com.jspsmart.upload.Request myRequest=new com.jspsmart.upload.Request();
//循环取得所有上载的文件
int imgNum = mySmartUpload.getFiles().getCount();
String type = mySmartUpload.getRequest().getParameter("type");
String magaid = mySmartUpload.getRequest().getParameter("magazineid");
String zj = mySmartUpload.getRequest().getParameter("zj");
String bm = mySmartUpload.getRequest().getParameter("bm");
String nr = mySmartUpload.getRequest().getParameter("content");
String fssj_yy = mySmartUpload.getRequest().getParameter("fssj_yy");
String fssj_mm = mySmartUpload.getRequest().getParameter("fssj_mm");
String fssj_dd = mySmartUpload.getRequest().getParameter("fssj_dd");
String fssj_s = mySmartUpload.getRequest().getParameter("fssj_s");
String fssj_f = mySmartUpload.getRequest().getParameter("fssj_f");
String fssj_m = mySmartUpload.getRequest().getParameter("fssj_m");
String sendtime = fssj_yy+","+fssj_mm+","+fssj_dd+","+fssj_s+","+fssj_f+","+fssj_m;
String ext = "";
String texturl = "";
String imgurl = "";
String bellurl = "";
//取得上载的文件
for (int i=0;i<imgNum;i++){
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
//取得上载的文件的文件名
String myFileName=myFile.getFileName();
//取得不带后缀的文件名
String suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
//取得后缀名
ext= mySmartUpload.getFiles().getFile(i).getFileExt();
//取得文件的大小
int fileSize=myFile.getSize()/1000;
//保存路径
//将文件保存在服务器端
String trace = ds.get("Wset")+"/source/img/maga/"+bm+"_"+zj+"."+ext;
myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
//下面的是将上载的文件保存到数据库中
//将文件读到流中
java.io.File file = new java.io.File(trace);
java.io.FileInputStream fis = new java.io.FileInputStream(file);
if(i==0)
imgurl = bm+"_"+zj+"."+ext;
else
bellurl = bm+"_"+zj+"."+ext;
}
}
outFile of = new outFile("",ds.get("Wset")+"/source/img/maga/",bm+"_"+zj+".txt");
of.makeTxtFile(to.getStr(nr),bm+"_"+zj+".txt");
texturl = bm+"_"+zj+".txt";
//将数据存入数据库
magaitem.save(magaid,texturl,bellurl,imgurl,sendtime);
%>
<form action=addmagaitem.jsp name="addform" method=post>
<input type="hidden" name="type" value="<%=type%>">
<input type="hidden" name="magazineid" value="<%=magaid%>">
<input type="hidden" name="zj" value="<%=Integer.parseInt(zj)+1%>">小说当前章节添加成功,是否添加该小说的下一章内容? <input class="bginput" type="submit" name="submit" value=" 确定 " >
<input class="bginput" type="button" name="" value=" 返回 " onclick="document.location.href='editmaga.jsp?type=<%=type%>'" > </form>
</form>
</body>
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
myFile.saveAs(getServletContext().getRealPath("/")+"upload\\" + fn);
在你的程序中。这句mySmartUpload.save("upload/");//文件保存的目录为upload
就是上传文件保存的目录,在这里使用的应该根路径,改成这样mySmartUpload.save("/upload/");就可以了,但是需要同时在根目录下面建立upload文件夹
你指定上传的路径一定要存在,否则就是这个错误!
我觉得"mySmartUpload.save("upload/");//文件保存的目录为upload" 有问题,但不知道怎么改呀?