<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="inewBean" scope="page" class="news.inewBean" />
<HTML>
<BODY BGCOLOR="white">
<H1>jspSmartUpload : Sample 3</H1>
<HR>
<%// Variables
int count=0;
// Initialization
mySmartUpload.initialize(pageContext);
// Only allow txt or htm files
//mySmartUpload.setAllowedFilesList("htm,html,txt,,");
// DeniedFilesList can also be used :
// mySmartUpload.setDeniedFilesList("exe,bat,jsp");
// Deny physical path
// mySmartUpload.setDenyPhysicalPath(true);
// Only allow files smaller than 50000 bytes
// mySmartUpload.setMaxFileSize(50000);
// Deny upload if the total fila size is greater than 200000 bytes
// mySmartUpload.setTotalMaxFileSize(200000);
// Upload
mySmartUpload.upload();
// Save the files with their original names in a virtual path of the web server
try {
count = mySmartUpload.save("/pic/upload/news", mySmartUpload.SAVE_VIRTUAL);
String title=mySmartUpload.getRequest().getParameter("title");
String content=mySmartUpload.getRequest().getParameter("content");
String picture=mySmartUpload.getFiles().getFile(0).getFileName();inewBean.insert_news(title,content,picture);
} catch (Exception e){
out.println("<b>Wrong selection : </b>" + e.toString());
}
// Display the number of files uploaded
out.println(count + " file(s) uploaded."); %>
</BODY>
</HTML>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="inewBean" scope="page" class="news.inewBean" />
<HTML>
<BODY BGCOLOR="white">
<H1>jspSmartUpload : Sample 3</H1>
<HR>
<%// Variables
int count=0;
// Initialization
mySmartUpload.initialize(pageContext);
// Only allow txt or htm files
//mySmartUpload.setAllowedFilesList("htm,html,txt,,");
// DeniedFilesList can also be used :
// mySmartUpload.setDeniedFilesList("exe,bat,jsp");
// Deny physical path
// mySmartUpload.setDenyPhysicalPath(true);
// Only allow files smaller than 50000 bytes
// mySmartUpload.setMaxFileSize(50000);
// Deny upload if the total fila size is greater than 200000 bytes
// mySmartUpload.setTotalMaxFileSize(200000);
// Upload
mySmartUpload.upload();
// Save the files with their original names in a virtual path of the web server
try {
count = mySmartUpload.save("/pic/upload/news", mySmartUpload.SAVE_VIRTUAL);
String title=mySmartUpload.getRequest().getParameter("title");
String content=mySmartUpload.getRequest().getParameter("content");
String picture=mySmartUpload.getFiles().getFile(0).getFileName();inewBean.insert_news(title,content,picture);
} catch (Exception e){
out.println("<b>Wrong selection : </b>" + e.toString());
}
// Display the number of files uploaded
out.println(count + " file(s) uploaded."); %>
</BODY>
</HTML>
我现在在WEB SERVE 上有个虚拟目录(uploadpic),我希望将用户上传的图片传到这个虚拟目录下。
JSPSMARTUPLOAD应该只能将上传的文件保存在实际的目录中。
File myDir = new File("uploadpic");
try{
myDir.mkdir();
}
catch(SecurityException e){
System.out.println(e.getMessage());
}
我就希望把用户上传的照片上传到我建立的目录:uploadpic下面,但我现在始终不能成功,郁闷~~~~~~~~~``
请大家指教!