我做了一个web上传bean,各位看看它的价值如何 up,我也刚学不久。他们不要,我要[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不错呵,不知道有没有这样的功能呵,我想上传一个已知文件名的文件,不是通过<input type=file>取得文件,再上传 。 不通过<input type=file>是没有办法得到上传文件的 不过你可以通过javascript对提交按钮做一个click函数,把一个普通表单的职付给file表单然后再提交 我想要,可以给我发一份吗?[email protected]先谢谢拉!!! 给我一份吧,谢谢拉!!![email protected] [email protected]学习,谢谢! 那也给我一份吧,[email protected] 谢谢了! [email protected] 感谢,支持奇文共欣赏 to jewzxm(zxm)你可能有个问题没讲明白。按你的意思是说你希望上传一个在客户端已知文件名的文件,但又不通过客户端的操作,服务器端直接完成??那岂不成了黑客程序了 也给我一份吧, [email protected] 谢谢了! 请帮我考虑这样一个问题,我希望在jsp中实现excel或者其他控件与表格的关联能够显示数据库里表的信息,而且能够在网页上就可以修改,并返回到数据库去, 呵!我正在学习文件上穿呢[email protected] you! 我也正在学习bean,可否探讨:[email protected] 兄弟,给我一份,谢谢![email protected] 大哥也给我来一份!EmailTo:[email protected]我顺便问一下,我有一个VIP客户验证,用到了数字证书,于是我要根据数据库里面提供的客户端数字证书filepath把file上传知服务端进行验证。此时,不知你的bean能否接受这个filepath呢?而不必要每次通过<input type="file".....去选择路径了!帮我考虑考虑! 来吧,给我。[email protected] 也给我一份学习学习[email protected] 我也要,学习一下,多谢![email protected] qnwa(眼巴巴望着程序) 在这贴出来不好吗?大家还可以一起研究一下. package weiupload;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import javax.servlet.jsp.PageContext;/** * <p>Title: weiupload</p> * <p>Description:web方式的文件上传组件</p> * <p>本程序在jBuilder6上开发完成,在tomcat3.2及tomcat4.01上测试通过。<p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: futurew</p> * @author qnwa(眼巴巴望着程序) * @version 1.0 */public class WeiUpload{ /**定义存放字段名的数组 */ private String[] fields=new String[1000]; /**定义存放字段值的数组 */ private String[] values=new String[1000]; /** 上传字段的总数量 */ private int fieldsCount; /** 服务器端存储上传文件的路径(默认路径为C:\\upload\\,若无此目录请先手工建立) */ private String savePath; /** 是否采用覆盖已有文件的存储方法 */ private boolean overWrite; private Hashtable fv=new Hashtable(); private Hashtable sfn=new Hashtable(); private HttpServletRequest weiRq=null; //private HttpServletResponse weiRp=null; /** 构造函数,设置变量初值 */ public WeiUpload() { fieldsCount=0; savePath="c:\\upload\\"; overWrite=false; } /** 初始化操作,从外部导入pageContext以得到相应的request */ public void initialize(PageContext pageContext) throws ServletException { weiRq=(HttpServletRequest)pageContext.getRequest(); //weiRp=(HttpServletResponse)pageContext.getResponse(); this.dealWith(weiRq); } /**处理request,从中分离出文件与字段,以及得到各种上传信息 */ public void dealWith(HttpServletRequest request) throws ServletException { try { //String content=request.getContentType(); int size=request.getContentLength(); DataInputStream in=new DataInputStream(request.getInputStream()); byte[] data=new byte[size]; int s=0,i=0,s_start=0,s_end=0; String disp=""; String sub; in.read(data); disp=new String(data,"ISO8859_1"); int start=disp.indexOf("name"); String boundary=disp.substring(0,start); int len=boundary.length(); int end=disp.indexOf(boundary,start); while(end>0) { sub=new String(data,start,end-start); s=sub.indexOf("\"",6); this.fields[i]=sub.substring(6,s); if(data[s+start+1]==13) { sub=sub.substring(s+5); sub=sub.substring(0,sub.length()-2); } else if(data[s+start+1]==59) { s_start=sub.indexOf("\"",s+1); s_end=sub.indexOf("\"",s_start+1); sub=sub.substring(s_start+1,s_end); if(sub.length()>0) sfn.put(this.fields[i],this.saveFile(data,disp.substring(start,end),start,end,sub)); } this.values[i]=sub; fv.put(this.fields[i],this.values[i]); i++; this.fieldsCount=i; start=end+len; end=disp.indexOf(boundary,start); } } catch(IOException e) {} } /**得到上传字段的字段名 */ public String getFieldName(int i) { return this.fields[i]; } /**得到与字段名相对应的字段值 */ public String getFieldValue(String fName) { if(this.fv.containsKey(fName.trim())) { String gFV=(String)this.fv.get(fName.trim()); return gFV; } return null; } /**得到文件被存储时的文件名 */ public String getSavedName(String fName) { if(this.fv.containsKey(fName.trim())) { String gSN=(String)this.sfn.get(fName.trim()); return gSN; } return null; } /**得到上传的字段值 */ public String getFieldValue(int i) { return this.values[i]; } /** 设置上传文件在服务器端的存储路径 */ public void setPath(String newPath) { this.savePath=newPath; } /**在上传的文件与存储目录中已有的文件重命时是覆盖还是自动换名存盘 */ public void setOverWrite(boolean b) { this.overWrite=b; } /** 得到上传字段的总共数量 */ public int getCount() { return this.fieldsCount; } /** 文件存储操作 */ private String saveFile(byte[] data,String fs,int start,int end,String filename) { FileOutputStream fileOut=null; File newFile; String newName=null; int s,p; try { s=fs.indexOf("Content-Type"); s=fs.indexOf("\r",s); p=filename.lastIndexOf("\\"); newName=filename.substring(p+1); if(this.overWrite) fileOut = new FileOutputStream(this.savePath+newName); else { fileOut = new FileOutputStream(newFile=checkFile(this.savePath,newName)); newName=newFile.getName(); } fileOut.write(data,start+s+4,end-start-s-6); fileOut.close(); } catch(Exception e) { System.out.print("errrrrrrrrr"); } return newName; } /** 判断是否有重命文件 */ private File checkFile(String path,String name) { File file=new File(path+name); int i=1; while(file.exists()) { file=new File(path+"("+i+")"+name); i++; } return file; }}我现在贴出所有源代码,各位给点意见吧,不过给我发邮件的朋友我还是会回复的!谢谢大家的厚爱,希望你们能喜欢我做的东东 能给我一份源码吗,我刚从其他语言转到java,想看看,[email protected] 一个特别奇怪的问题? 请问怎么播放mov格式的文件 多维度数据如何在jsp网页中显示 我在J2EE项目中的jsp页面里嵌入了一个applet小程序,客户端正常运行需要装Java虚拟机吗 poi 导入大量数据到excel内存溢出,在线等 thickbox 弹出页面问题 如何使用JSP实现一个页面中点击查询,在本页面下面显示结果 求教一个javascript 小弟初学jsp,查找/替换函数忘了~那位指点?在线等待~~ 欢迎灌水。。。。。。 在Jsp文件中如何控制页面没秒钟刷新一次 servlet问题
[email protected]
先谢谢拉!!!
[email protected]
学习,谢谢!
能够显示数据库里表的信息,而且能够在网页上就可以修改,并返回到数据库去,
[email protected] you!
[email protected]
EmailTo:[email protected]
我顺便问一下,我有一个VIP客户验证,用到了数字证书,于是我要根据数据库里面提供的客户端数字证书filepath把file上传知服务端进行验证。
此时,不知你的bean能否接受这个filepath呢?而不必要每次通过<input type="file".....
去选择路径了!
帮我考虑考虑!
[email protected]
大家还可以一起研究一下.
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.servlet.jsp.PageContext;/**
* <p>Title: weiupload</p>
* <p>Description:web方式的文件上传组件</p>
* <p>本程序在jBuilder6上开发完成,在tomcat3.2及tomcat4.01上测试通过。<p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: futurew</p>
* @author qnwa(眼巴巴望着程序)
* @version 1.0 */public class WeiUpload
{
/**定义存放字段名的数组 */
private String[] fields=new String[1000];
/**定义存放字段值的数组 */
private String[] values=new String[1000];
/** 上传字段的总数量 */
private int fieldsCount;
/** 服务器端存储上传文件的路径(默认路径为C:\\upload\\,若无此目录请先手工建立) */
private String savePath;
/** 是否采用覆盖已有文件的存储方法 */
private boolean overWrite;
private Hashtable fv=new Hashtable();
private Hashtable sfn=new Hashtable();
private HttpServletRequest weiRq=null;
//private HttpServletResponse weiRp=null; /** 构造函数,设置变量初值 */
public WeiUpload()
{
fieldsCount=0;
savePath="c:\\upload\\";
overWrite=false;
} /** 初始化操作,从外部导入pageContext以得到相应的request */
public void initialize(PageContext pageContext) throws ServletException
{
weiRq=(HttpServletRequest)pageContext.getRequest();
//weiRp=(HttpServletResponse)pageContext.getResponse();
this.dealWith(weiRq);
} /**处理request,从中分离出文件与字段,以及得到各种上传信息 */
public void dealWith(HttpServletRequest request) throws ServletException
{
try
{
//String content=request.getContentType();
int size=request.getContentLength();
DataInputStream in=new DataInputStream(request.getInputStream());
byte[] data=new byte[size];
int s=0,i=0,s_start=0,s_end=0;
String disp="";
String sub;
in.read(data);
disp=new String(data,"ISO8859_1");
int start=disp.indexOf("name");
String boundary=disp.substring(0,start);
int len=boundary.length();
int end=disp.indexOf(boundary,start);
while(end>0)
{
sub=new String(data,start,end-start);
s=sub.indexOf("\"",6);
this.fields[i]=sub.substring(6,s);
if(data[s+start+1]==13)
{
sub=sub.substring(s+5);
sub=sub.substring(0,sub.length()-2);
}
else if(data[s+start+1]==59)
{
s_start=sub.indexOf("\"",s+1);
s_end=sub.indexOf("\"",s_start+1);
sub=sub.substring(s_start+1,s_end);
if(sub.length()>0)
sfn.put(this.fields[i],this.saveFile(data,disp.substring(start,end),start,end,sub));
}
this.values[i]=sub;
fv.put(this.fields[i],this.values[i]);
i++;
this.fieldsCount=i;
start=end+len;
end=disp.indexOf(boundary,start);
}
}
catch(IOException e)
{}
} /**得到上传字段的字段名 */
public String getFieldName(int i)
{
return this.fields[i];
} /**得到与字段名相对应的字段值 */
public String getFieldValue(String fName)
{
if(this.fv.containsKey(fName.trim()))
{
String gFV=(String)this.fv.get(fName.trim());
return gFV;
}
return null;
} /**得到文件被存储时的文件名 */
public String getSavedName(String fName)
{
if(this.fv.containsKey(fName.trim()))
{
String gSN=(String)this.sfn.get(fName.trim());
return gSN;
}
return null;
} /**得到上传的字段值 */
public String getFieldValue(int i)
{
return this.values[i];
} /** 设置上传文件在服务器端的存储路径 */
public void setPath(String newPath)
{
this.savePath=newPath;
} /**在上传的文件与存储目录中已有的文件重命时是覆盖还是自动换名存盘 */
public void setOverWrite(boolean b)
{
this.overWrite=b;
} /** 得到上传字段的总共数量 */
public int getCount()
{
return this.fieldsCount;
} /** 文件存储操作 */
private String saveFile(byte[] data,String fs,int start,int end,String filename)
{
FileOutputStream fileOut=null;
File newFile;
String newName=null;
int s,p;
try
{
s=fs.indexOf("Content-Type");
s=fs.indexOf("\r",s);
p=filename.lastIndexOf("\\");
newName=filename.substring(p+1);
if(this.overWrite)
fileOut = new FileOutputStream(this.savePath+newName);
else
{
fileOut = new FileOutputStream(newFile=checkFile(this.savePath,newName));
newName=newFile.getName();
}
fileOut.write(data,start+s+4,end-start-s-6);
fileOut.close();
}
catch(Exception e)
{
System.out.print("errrrrrrrrr");
}
return newName;
} /** 判断是否有重命文件 */
private File checkFile(String path,String name)
{
File file=new File(path+name);
int i=1;
while(file.exists())
{
file=new File(path+"("+i+")"+name);
i++;
}
return file;
}
}我现在贴出所有源代码,各位给点意见吧,不过给我发邮件的朋友我还是会回复的!谢谢大家的厚爱,希望你们能喜欢我做的东东