按以下方式调mySmartUpload的方法即可<%@page contentType="text/html;charset=gb2312"%> <%@ page language="java" import="com.htyz.fileUtil.*"%> <jsp:useBean id="mySmartUpload" scope="page" class="com.htyz.fileUtil.UploadFiles" /><HTML> <BODY BGCOLOR="white"> <% // Variables int count=0; // Initialization mySmartUpload.initialize(pageContext); // Upload mySmartUpload.upload(); try { // Save the files with their original names in the virtual path "/upload" // if it doesn't exist try to save in the physical path "/upload" count = mySmartUpload.save("/elearning/news/upload/");
//filename="http://"+"/upload/mysmartUpload.getFieldName()" // Save the files with their original names in the virtual path "/upload" // count = mySmartUpload.save("/upload", mySmartUpload.SAVE_VIRTUAL); // Display the number of files uploaded out.println(count + " file(s) uploaded."); } catch (Exception e) { out.println(e.toString()); }
有没有说明什么的。
jspsmartupload是不是得注册啊?
不注册是不是有时间限制啊?
信箱[email protected]
谢谢!
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.PageContext;public class yuanyifileup
{
private ServletRequest request;
private ServletResponse response;
private ServletConfig config;
ServletInputStream DATA;
int FormSize;
File f1;
FileOutputStream os;
DataInputStream is;
String filename;
byte[] b;
byte t;
boolean flag=false;
public yuanyifileup()
{ }
public void initialize(ServletConfig config,HttpServletRequest request,HttpServletResponse response) throws IOException
{
this.request=request;
this.response=response;
this.config=config;
DATA = request.getInputStream();
FormSize=request.getContentLength();
}
public void initialize(PageContext pageContext) throws IOException
{
request=pageContext.getRequest();
response=pageContext.getResponse();
config=pageContext.getServletConfig();
DATA = request.getInputStream();
FormSize=request.getContentLength();
}
public boolean setFilename(String s)
{
try
{
File f1=new File(s);
os=new FileOutputStream(f1);
}
catch(IOException e)
{return(false);}
return(true);
}
public void getByte()
{
int i=0;
try
{
is=new DataInputStream(DATA);
b=new byte[FormSize];while (true)
{
try
{
t=is.readByte();
b[i]=t;
i++;
}
catch(EOFException e)
{ break;}
}
is.close();}
catch(IOException e)
{}
}public boolean save()
{
int i=0,start1=0,start2=0;
String temp="";
if (!flag)
{
getByte();
flag=true;
}
try
{
temp=new String(b,"ISO8859_1");
}
catch(UnsupportedEncodingException e)
{return(false);}start1=temp.indexOf("image/");
temp=temp.substring(start1);start1=temp.indexOf("\r\n\r\n");temp=temp.substring(start1+4);
start2=temp.indexOf(";\r\n");
if (start2!=-1)
{
temp=temp.substring(0,start2);
}
try
{
byte[] img=temp.getBytes("ISO8859_1");
for (i=0;i<img.length;i++)
{ os.write(img[i]); }
os.close();
}
catch(IOException e)
{return(false);}return(true);}}
<%@ page language="java" import="com.htyz.fileUtil.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.htyz.fileUtil.UploadFiles" /><HTML>
<BODY BGCOLOR="white">
<% // Variables
int count=0; // Initialization
mySmartUpload.initialize(pageContext); // Upload
mySmartUpload.upload();
try { // Save the files with their original names in the virtual path "/upload"
// if it doesn't exist try to save in the physical path "/upload"
count = mySmartUpload.save("/elearning/news/upload/");
out.println(mySmartUpload.getFiles().getFile(0).getFileName());
//filename="http://"+"/upload/mysmartUpload.getFieldName()"
// Save the files with their original names in the virtual path "/upload"
// count = mySmartUpload.save("/upload", mySmartUpload.SAVE_VIRTUAL); // Display the number of files uploaded
out.println(count + " file(s) uploaded."); } catch (Exception e) {
out.println(e.toString());
}
%>
<script>
alert("<%=mySmartUpload.getFiles().getFile(0).getFileName()%>文件被上传!");
/* 还要把上传的文件名称加入到上传界面的下拉列表中 */
</script>
</BODY>
</HTML>
我是刚开始接触这儿,
因此不明白,呵呵。
那个Apache + Jserv 要运行JSP是不是得再安装gnujsp啊?
没有那个文件是不是还不能解析JSP?
还有yuanyifileup是不是存成yuanyifileup.class放到servlets目录下?
最好给我一个例子!
我是对这个一点也不明白哦.......
真是伤心