这就是我下载的jspsmartupload包中的上传程序,里面的方法怎么都是空的啊,它的示例程序也不能个上传,郁闷,package com.upload;// Imports
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;public class SmartUpload { // Fields
protected byte[] m_binArray;
protected HttpServletRequest m_request;
protected HttpServletResponse m_response;
protected ServletContext m_application;
private int m_totalBytes;
private int m_currentIndex;
private int m_startData;
private int m_endData;
private String m_boundary;
private long m_totalMaxFileSize;
private long m_maxFileSize;
private Vector m_deniedFilesList;
private Vector m_allowedFilesList;
private boolean m_denyPhysicalPath;
private boolean m_forcePhysicalPath;
private String m_contentDisposition;
public static final int SAVE_AUTO = 0;
public static final int SAVE_VIRTUAL = 1;
public static final int SAVE_PHYSICAL = 2;
private Files m_files;
private Request m_formRequest; // Constructors
public SmartUpload() { } // Methods
public final void init(ServletConfig servletConfig) throws ServletException { }
public void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { }
public final void initialize(ServletConfig servletConfig, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException { }
public final void initialize(PageContext pageContext) throws ServletException { }
public final void initialize(ServletContext servletContext, HttpSession httpSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, JspWriter jspWriter) throws ServletException { }
public void upload() throws ServletException, IOException, SmartUploadException { }
public int save(String string) throws ServletException, IOException, SmartUploadException { return 0;}
public int save(String string, int int1) throws ServletException, IOException, SmartUploadException { return 0;}
public int getSize() { return 0;}
public byte getBinaryData(int int0) { return 0;}
public Files getFiles() { return null;}
public Request getRequest() { return null;}
public void downloadFile(String string) throws ServletException, IOException, SmartUploadException { }
public void downloadFile(String string, String string1) throws ServletException, IOException, SmartUploadException, SmartUploadException { }
public void downloadFile(String string, String string1, String string2) throws ServletException, IOException, SmartUploadException { }
public void downloadFile(String string, String string1, String string2, int int3) throws ServletException, IOException, SmartUploadException { }
public void downloadField(ResultSet resultSet, String string, String string2, String string3) throws ServletException, IOException, SQLException { }
public void fieldToFile(ResultSet resultSet, String string, String string2) throws ServletException, IOException, SmartUploadException, SQLException { }
private String getDataFieldValue(String string, String string1) { return null;}
private String getFileExt(String string) { return null;}
private String getContentType(String string) { return null;}
private String getTypeMIME(String string) { return null;}
private String getSubTypeMIME(String string) { return null;}
private String getContentDisp(String string) { return null;}
private void getDataSection() { }
private String getDataHeader() { return null;}
private String getFileName(String string) { return null;}
public void setDeniedFilesList(String string) throws ServletException, IOException, SQLException { }
public void setAllowedFilesList(String string) { }
public void setDenyPhysicalPath(boolean boolean0) { }
public void setForcePhysicalPath(boolean boolean0) { }
public void setContentDisposition(String string) { }
public void setTotalMaxFileSize(long long0) { }
public void setMaxFileSize(long long0) { }
protected String getPhysicalPath(String string, int int1) throws IOException { return null;}
public void uploadInFile(String string) throws IOException, SmartUploadException { }
private boolean isVirtual(String string) { return false;}
}
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;public class SmartUpload { // Fields
protected byte[] m_binArray;
protected HttpServletRequest m_request;
protected HttpServletResponse m_response;
protected ServletContext m_application;
private int m_totalBytes;
private int m_currentIndex;
private int m_startData;
private int m_endData;
private String m_boundary;
private long m_totalMaxFileSize;
private long m_maxFileSize;
private Vector m_deniedFilesList;
private Vector m_allowedFilesList;
private boolean m_denyPhysicalPath;
private boolean m_forcePhysicalPath;
private String m_contentDisposition;
public static final int SAVE_AUTO = 0;
public static final int SAVE_VIRTUAL = 1;
public static final int SAVE_PHYSICAL = 2;
private Files m_files;
private Request m_formRequest; // Constructors
public SmartUpload() { } // Methods
public final void init(ServletConfig servletConfig) throws ServletException { }
public void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { }
public final void initialize(ServletConfig servletConfig, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException { }
public final void initialize(PageContext pageContext) throws ServletException { }
public final void initialize(ServletContext servletContext, HttpSession httpSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, JspWriter jspWriter) throws ServletException { }
public void upload() throws ServletException, IOException, SmartUploadException { }
public int save(String string) throws ServletException, IOException, SmartUploadException { return 0;}
public int save(String string, int int1) throws ServletException, IOException, SmartUploadException { return 0;}
public int getSize() { return 0;}
public byte getBinaryData(int int0) { return 0;}
public Files getFiles() { return null;}
public Request getRequest() { return null;}
public void downloadFile(String string) throws ServletException, IOException, SmartUploadException { }
public void downloadFile(String string, String string1) throws ServletException, IOException, SmartUploadException, SmartUploadException { }
public void downloadFile(String string, String string1, String string2) throws ServletException, IOException, SmartUploadException { }
public void downloadFile(String string, String string1, String string2, int int3) throws ServletException, IOException, SmartUploadException { }
public void downloadField(ResultSet resultSet, String string, String string2, String string3) throws ServletException, IOException, SQLException { }
public void fieldToFile(ResultSet resultSet, String string, String string2) throws ServletException, IOException, SmartUploadException, SQLException { }
private String getDataFieldValue(String string, String string1) { return null;}
private String getFileExt(String string) { return null;}
private String getContentType(String string) { return null;}
private String getTypeMIME(String string) { return null;}
private String getSubTypeMIME(String string) { return null;}
private String getContentDisp(String string) { return null;}
private void getDataSection() { }
private String getDataHeader() { return null;}
private String getFileName(String string) { return null;}
public void setDeniedFilesList(String string) throws ServletException, IOException, SQLException { }
public void setAllowedFilesList(String string) { }
public void setDenyPhysicalPath(boolean boolean0) { }
public void setForcePhysicalPath(boolean boolean0) { }
public void setContentDisposition(String string) { }
public void setTotalMaxFileSize(long long0) { }
public void setMaxFileSize(long long0) { }
protected String getPhysicalPath(String string, int int1) throws IOException { return null;}
public void uploadInFile(String string) throws IOException, SmartUploadException { }
private boolean isVirtual(String string) { return false;}
}
解决方案 »
- String.matches(String regex)的问题
- 我希望实现一个jsp发邮件的功能,网上的出现各种错。跪求一份没错的。。。
- 在jsp/html页面中合并单元格
- 关于多级栏目实现动态复选框的问题
- 高分,求救高手!!!!!!!!!
- 求高人指教,关于cookie的问题
- jasper report 提问????
- out4=out4.replaceAll(chr(32)," "); 出错?多谢大家。
- 关于getRealPath()!
- 为了少走弯路,我说一下我看了n篇帖子,尝试了n个月到现在才搞懂的一个问题:JavaBean的使用。
- <meta HTTP_EQUIV="Refresh" content="3">当刷新页面时,如何让IE状态条不出现进度条
- 请问Apache和Tomcat有什么相同和不同之处?区别?
你看看上面的方法怎么都是空的啊
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java" import="com.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.upload.SmartUpload" /><HTML>
<BODY BGCOLOR="white">
<H1>jspSmartUpload : Sample 1</H1>
<HR><%//实例化上载bean
int count=0;
//初始化
mySmartUpload.initialize(pageContext);
//设置上载的最大值
mySmartUpload.setMaxFileSize(500 * 1024*1024);
//上载文件
mySmartUpload.upload();
//循环取得所有上载的文件
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
//取得上载的文件
com.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
//取得上载的文件的文件名
String myFileName=myFile.getFileName();
//取得不带后缀的文件名
String suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
//取得后缀名
String ext= mySmartUpload.getFiles().getFile(0).getFileExt();
//取得文件的大小
int fileSize=myFile.getSize();
//保存路径
String aa=getServletContext().getRealPath("../upload/");
String trace=aa+myFileName;
//取得别的参数
// String explain=(String)mySmartUpload.getRequest().getParameter("filename");
// String send=(String)mySmartUpload.getRequest().getParameter("");
//将文件保存在服务器端
myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
}//end if
else{
out.println(("上载失败!!!").toString());
}//end else
count++;
}//end for
out.print(count+": 个文件被上传");
%>
</BODY>
</HTML>
<%@ page contentType="text/html;charset=gb2312"%>
<HTML>
<BODY BGCOLOR="white"><H1>jspSmartUpload : Sample 4</H1>
<HR><FORM METHOD="POST" ACTION="upload.jsp" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="filename" SIZE="20"><BR>
<INPUT TYPE="SUBMIT" VALUE="上传">
</FORM></BODY>
</HTML>
我下载的jspsmartupload里面的方法怎么都是空的啊,怎么能够上传呢?
你们怎么用的啊,是直接用它的包吗?我在上面已经把smartupload.java的程序帖出来了,你看看方法都是空的,能用吗?
你有上传的例子吗,给我一个好吗,谢谢了大哥!
谢谢各位了,能不能把你们的jspsmartupload.java发给我一份谢谢!
以下是我找到的例子
package com.upload;import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletException;public class upload{
private static String newline = "\n";
private String uploadDirectory = ".";
private String ContentType = "";
private String CharacterEncoding = "";//得到上传的文件名
private String getFileName(String s){
int i = s.lastIndexOf("\\");
if(i < 0 || i >= s.length() - 1){
i = s.lastIndexOf("/");
if(i < 0 || i >= s.length() - 1)
return s;
}
return s.substring(i + 1);
}//设置上传的文件路径
public void setUploadDirectory(String s){
uploadDirectory = s;
}//上传文件的内容
public void setContentType(String s){
ContentType = s;
int j;
if((j = ContentType.indexOf("boundary=")) != -1){
ContentType = ContentType.substring(j + 9);
ContentType = "--" + ContentType;
}
}//上传编码的格式
public void setCharacterEncoding(String s){
CharacterEncoding = s;
}//上传文件
public void uploadFile( HttpServletRequest req) throws ServletException, IOException{
setCharacterEncoding(req.getCharacterEncoding()); //国际编码标准
setContentType(req.getContentType());
uploadFile(req.getInputStream());
}public void uploadFile( ServletInputStream servletinputstream) throws ServletException, IOException{String s5 = null;
String filename = null;
byte Linebyte[] = new byte[4096];
byte outLinebyte[] = new byte[4096];
int ai[] = new int[1];
int ai1[] = new int[1];String line;//得到文件名while((line = readLine(Linebyte, ai, servletinputstream, CharacterEncoding)) != null){
int i = line.indexOf("filename=");
if(i >= 0){
line = line.substring(i + 10);
if((i = line.indexOf("\"")) > 0)
line = line.substring(0, i);
break;
}
}filename = line;if(filename != null && !filename.equals("\"")){
filename = getFileName(filename);String sContentType = readLine(Linebyte, ai, servletinputstream, CharacterEncoding);
if(sContentType.indexOf("Content-Type") >= 0)
readLine(Linebyte, ai, servletinputstream, CharacterEncoding);//File(String parent, String child)
//Creates a new File instance from a parent pathname string
//and a child pathname string.
File file = new File(uploadDirectory, filename);//FileOutputStream(File file)
//Creates a file output stream to write to the file represented
//by the specified File object.
//输出上传的文件
FileOutputStream fileoutputstream = new FileOutputStream(file);while((sContentType = readLine(Linebyte, ai, servletinputstream, CharacterEncoding)) != null){
if(sContentType.indexOf(ContentType) == 0 && Linebyte[0] == 45)
break;if(s5 != null){
//write(byte[] b, int off, int len)
//Writes len bytes from the specified byte array starting
//at offset off to this file output stream.
fileoutputstream.write(outLinebyte, 0, ai1[0]);
fileoutputstream.flush();
}
s5 = readLine(outLinebyte, ai1, servletinputstream, CharacterEncoding);
if(s5 == null || s5.indexOf(ContentType) == 0 && outLinebyte[0] == 45)
break;
fileoutputstream.write(Linebyte, 0, ai[0]);
fileoutputstream.flush();
}byte byte0;
if(newline.length() == 1)
byte0 = 2;
else
byte0 = 1;
if(s5 != null && outLinebyte[0] != 45 && ai1[0] > newline.length() * byte0)
fileoutputstream.write(outLinebyte, 0, ai1[0] - newline.length() * byte0);
if(sContentType != null && Linebyte[0] != 45 && ai[0] > newline.length() * byte0)
fileoutputstream.write(Linebyte, 0, ai[0] - newline.length() * byte0);fileoutputstream.close();
}
}//读上传文件的内容
private String readLine(byte Linebyte[], int ai[],
ServletInputStream servletinputstream,
String CharacterEncoding){
try{
//readLine(byte[] buffer, int offset, int length)
//Reads a line from the POST data.
ai[0] = servletinputstream.readLine(Linebyte, 0, Linebyte.length);
if(ai[0] == -1)
return null;
}catch(IOException _ex){
return null;
}
try{
if(CharacterEncoding == null){
//用缺省的编码方式把给定的byte数组转换为字符串
//String(byte[] bytes, int offset, int length)
return new String(Linebyte, 0, ai[0]);
}else{
//用给定的编码方式把给定的byte数组转换为字符串
//String(byte[] bytes, int offset, int length, String enc)
return new String(Linebyte, 0, ai[0], CharacterEncoding);
}
}catch(Exception _ex){
return null;
}
}
/*
public int readLine(byte[] buffer,
int offset,
int length) throws java.io.IOException
从POST来的数据中读一行
参数:
buffer - buffer to hold the line data
offset - offset into the buffer to start
length - maximum number of bytes to read.
Returns:
number of bytes read or -1 on the end of line.
*/
}
<%@ page contentType="text/html;charset=gb2312"%>
<%@page import="com.upload.*"%>
<%
String Dir = "f:/upload/";upload upload = new upload();
upload.setUploadDirectory(Dir);
upload.uploadFile(request);
out.print("<html><body><center><font color=red>成功上载文件至" + Dir + "</font></center></body></html>");
%>upload.html
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java" import="com.upload.*"%>
<HTML>
<BODY BGCOLOR="white">
<center>
<H2><font color=blue>上传工资文件的结果</font></H2>
<HR>
<%
String Dir = "f:/upload/"; upload upload = new upload();
upload.setUploadDirectory(Dir);
upload.uploadFile(request);
out.print("<font color=red>成功上载文件至" + Dir + "</font>");
%>
</center>
</BODY>
</HTML>