客户端就一个图片的绝对地址,怎么通过文件流远程上传到服务器去? jsp页面<input type="text" value="图片的绝对地址">有没有办法远程上传到服务器 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上传jsp<%@ page contentType="text/html;charset=gb2312" %><head><title>fbysss UploadBean 示例</title><!--meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"--><!--meta http-equiv="Content-Type" content="text/html; charset=gb2312"--></head><FORM name="form1" METHOD="POST" ACTION="sssupload.jsp" ENCTYPE="multipart/form-data"><input name="title" type= "text" value="中文字"><td class="bodystyle">附件</td><td class="bodystyle"> <input name="attach" type="FILE" id="attach" size="50" > </td><input name="ok" type= "submit" value="提交"></form>处理的jsp(sssgetdata.jsp)用servlet也可以[code=HTML]<%@ page contentType="text/html;charset=GBK" %><%@ page language="java" import="com.jspsmart.upload.*"%><%@ page import="java.text.SimpleDateFormat"%><%@ page import="java.io.File"%><%@ page import="java.util.*"%><%@ page import="javazoom.upload.*"%><%@ page import="uploadutilities.FileMover"%><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><% request.setCharacterEncoding("GBK");//设置编码格式,就不用一个个转码了。FileMover fileMover = new FileMover();//你也可以使用自带的实例中jsp:useBean的形式。UploadBean upBean = new UploadBean();MultipartFormDataRequest mrequest = null;Hashtable files = null;if (MultipartFormDataRequest.isMultipartFormData(request)){mrequest = new MultipartFormDataRequest(request,null,100*1024*1024,MultipartFormDataRequest.COSPARSER,"GBK");//注意这里也要设置编码参数String sTt0 = mrequest.getParameter("title");out.println("<br>Title0是:"+sTt0+"<br>");String sTt1 = new String(sTt0.getBytes("ISO-8859-1"),"GBK");out.println("<br>Title1是:"+sTt1+"<br>");//这里用来测试title参数是否正确。调试的时候,加一句if (true)return;即可。files = mrequest.getFiles();}//获取修改前的文件名String sOldFileName =mrequest.getParameter("oldfilename"); out.println("sOldFileName:"+sOldFileName);String sWebRootPath = request.getRealPath("/");//得到你的web应用的根。String sPath=sWebRootPath+"attach";int iFileCount = 0;String sServerFileName="";String sLocalFileName = "";//文件获取if ( (files != null) || (!files.isEmpty()) ) {iFileCount = files.size();UploadFile file = (UploadFile) files.get("attach");sLocalFileName=file.getFileName();out.println("sLocalFileName:"+sLocalFileName);int ii= sLocalFileName.indexOf("."); //取文件名的后缀String sExt = sLocalFileName.substring(ii,sLocalFileName.length());//得到不重复的文件名java.util.Date dt = new java.util.Date(System.currentTimeMillis());SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");sServerFileName= fmt.format(dt);sServerFileName =sServerFileName + sExt;//如果不存在该目录,则新建一个File dir =new File(sPath);if (!dir.exists()){dir.mkdirs();}upBean.setFolderstore(sPath);//设置要上传的目录upBean.addUploadListener(fileMover);//增加filMover监听fileMover.setNewfilename(sServerFileName);//设置服务器上的文件名upBean.store(mrequest, "attach");//上传out.println("file path is "+sPath+"/"+sServerFileName);}%>[/code] 前台页面代码<tr><td>廣告路徑: <input type="file" name="myFile" id="advertPath"> </td></tr>action中定义这些属性,并提供set,get方法,此处省略 private File myFile; private String myFileFileName; private TblAdvert tblAdvert; private String fileName;public void setMyFileFileName(String fileName) { System.out.println("myFileFileName為:"+myFileFileName); this.myFileFileName = fileName; } private static void copy(File src, File dst) { try { InputStream in = null ; OutputStream out = null ; try { in = new BufferedInputStream( new FileInputStream(src), 16 * 1024); out = new BufferedOutputStream( new FileOutputStream(dst), 16 * 1024); byte [] buffer = new byte [16 * 1024]; while (in.read(buffer) > 0 ) { out.write(buffer); } } finally { if ( null != in) { in.close(); } if ( null != out) { out.close(); } } } catch (Exception e) { e.printStackTrace(); } } public String addposter(){ System.out.println("進入到增加方法里了"); int pos = myFileFileName.lastIndexOf("."); fileName = new Date().getTime()+ myFileFileName.substring(pos); File dst = new File(ServletActionContext.getServletContext().getRealPath("/UploadImages" ) + "/" + fileName); copy(myFile, dst); tblAdvert.setAdvertPath(fileName); Session session = HibernateSessionFactory.getSession(); Transaction tx = session.beginTransaction(); try { session.save(tblAdvert); tx.commit(); System.out.println("save success"); } catch (Exception e) { tx.rollback(); e.printStackTrace(); }finally{ session.close(); } return "addposterOk"; } JSP本来就是服务器端的东西,你的绝对路径是什么?难道是客户端的绝对路径。按道理来说,上传必须是客户端发启的。不然你代码中写个文件路径,想要什么文件就能偷什么文件了。 首先感谢你们回答但是这个不是我想要的我现在的问题是我用二代身份证扫描机扫描身份证(一扫描身份证就得把图片上传到服务器去)身份证信息显示到文本框里去这个都没问题然后它会自动生成一张图片,就是身份证上面的头像默认在C盘怎么把c盘的图片上传到我的服务器中不是点浏览,没有用到这个<input type="file">而是<input type="text" value="图片的绝对路径"> 是客户端的路径,打个比方,比如说你D盘的图片,d:\a.jpg<input type="text" value="d:\a.jpg">jsp页面文本框就是现实你d盘图片有没有办法上传到我服务器上 你这个是不是用到了applet 还是有什么别的东西, 不然是怎么让浏览器拿到扫描仪的数据,要是有用到的话,就用java ftp吧,浏览器就算了。只通过浏览器基本没可能实现这上传的功能的。我是不知道。 这个是完全可以的。只需要借助于一个ActiveX控件就行了。Xproer.HttpUploader:http://www.cnblogs.com/xproer/archive/2010/10/24/1859895.html此控件是基于标准HTTP协议实现的文件上传功能。优势是扩展性非常好,整合简单,支持批量上传文件和上传文件夹功能,适合各种简单WEB项目。另外一个特点是支持自动上传指定的本地文件。单文件上传演示上传本地文件代码使用步骤如下:1.调用AddFile函数添加本地文件,注意路径需要使用双斜框(\\)2.调用PostFirst函数开始上传文件。<script type="text/javascript" language="javascript"> var uploaderMgr = new HttpUploaderMgr(); uploaderMgr.Load();//加载控件 window.onload = function() { uploaderMgr.Init();//初始化控件 //添加一个本地文件 uploaderMgr.AddFile("D:\\Soft\\QQ2010.exe"); uploaderMgr.PostFirst(); };</script> 单文件整合代码: 服务器返回消息:<input id="txtFilePath" type="text" size="50" /> <script type="text/javascript" language="javascript"> var uploaderMgr = new HttpUploaderSingleMgr(); uploaderMgr.Config["PostUrl"] = "http://localhost:8080/asp.net/upload.aspx"; uploaderMgr.Load(); //文件上传完成后执行的回调函数 uploaderMgr.CompleteHook = function(msg) { document.getElementById("txtFilePath").value = msg; }; window.onload = function() { uploaderMgr.Init(); }; </script> 这个用到了OCX,但是OCX没办法上传 我们之前做了一个和楼主类似的项目,这个需求实际就是通过JS将本地指定路径的文件上传到服务器中。普通的JS是没办法来实现这个功能的,我们是用的Xproer.HttpUploader这个控件来实现的这个功能。 如果这样可以的话,你这样的网站我可不敢打开了,你这样弄几下就把我电脑上的文件给传到了服务器,NND,哥的私生活全都要曝光了 这个给个地址就能够上传了。从示例代码中你可以看出来通过本地路径就能够上传。<script type="text/javascript" language="javascript"> var uploaderMgr = new HttpUploaderMgr(); uploaderMgr.Load();//加载控件 window.onload = function() { uploaderMgr.Init();//初始化控件 //添加一个本地文件,在这里指定本地文件的路径。 uploaderMgr.AddFile("D:\\Soft\\QQ2010.exe"); uploaderMgr.PostFirst(); };</script> 楼上说的对如果不想花钱的话,用commons-fileupload-1.1.1.jar也不错 这样现在我服务器在北京你人在广州可以通过外网访问系统然后你有个身份证扫描器,一扫描身份证,可以把信息都显示到jsp<input type="text" value="张三><input type="text" value="男">等等当然这些value都是通过OCX来获取的同时这个身份证扫描机会在你自己的机子上生成一个图片,就是你身份证上面的头像,默认保存路劲C:\Program Files\Internet Explorer\tmp.bmp这个也可以扫描到jsp去<input type="text" value="C:\Program Files\Internet Explorer\tmp.bmp">就类似这样但是这只是一个绝对地址,我怎么上传到我服务器? stuts2 框架struts2标记 需找一个懂lucene的高手, 请教,关于Ruby语言 JPA 整合SPRING 出现的 问题 大家现在都用什么框架 AXIS如何自定义XML格式 基于jboss的axis web service权限问题 J2EE应用程序客户端 输入用户和密码后报错? java 编译出错 请大家看一段话?编辑通过,运行出现问题! 急急急 java线程池问题 关于锁定数据的问题
<head>
<title>fbysss UploadBean 示例</title>
<!--meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"-->
<!--meta http-equiv="Content-Type" content="text/html; charset=gb2312"-->
</head>
<FORM name="form1" METHOD="POST" ACTION="sssupload.jsp" ENCTYPE="multipart/form-data">
<input name="title" type= "text" value="中文字">
<td class="bodystyle">附件</td>
<td class="bodystyle"> <input name="attach" type="FILE" id="attach" size="50" > </td>
<input name="ok" type= "submit" value="提交">
</form>
处理的jsp(sssgetdata.jsp)用servlet也可以
[code=HTML]
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.io.File"%>
<%@ page import="java.util.*"%>
<%@ page import="javazoom.upload.*"%>
<%@ page import="uploadutilities.FileMover"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<%
request.setCharacterEncoding("GBK");//设置编码格式,就不用一个个转码了。
FileMover fileMover = new FileMover();//你也可以使用自带的实例中jsp:useBean的形式。
UploadBean upBean = new UploadBean();
MultipartFormDataRequest mrequest = null;
Hashtable files = null;if (MultipartFormDataRequest.isMultipartFormData(request))
{
mrequest = new MultipartFormDataRequest(request,null,100*1024*1024,MultipartFormDataRequest.COSPARSER,"GBK");//注意这里也要设置编码参数
String sTt0 = mrequest.getParameter("title");
out.println("<br>Title0是:"+sTt0+"<br>");
String sTt1 = new String(sTt0.getBytes("ISO-8859-1"),"GBK");
out.println("<br>Title1是:"+sTt1+"<br>");
//这里用来测试title参数是否正确。调试的时候,加一句if (true)return;即可。
files = mrequest.getFiles();
}
//获取修改前的文件名
String sOldFileName =mrequest.getParameter("oldfilename");
out.println("sOldFileName:"+sOldFileName);
String sWebRootPath = request.getRealPath("/");//得到你的web应用的根。
String sPath=sWebRootPath+"attach";
int iFileCount = 0;
String sServerFileName="";
String sLocalFileName = "";
//文件获取
if ( (files != null) || (!files.isEmpty()) ) {iFileCount = files.size();
UploadFile file = (UploadFile) files.get("attach");
sLocalFileName=file.getFileName();
out.println("sLocalFileName:"+sLocalFileName);
int ii= sLocalFileName.indexOf("."); //取文件名的后缀
String sExt = sLocalFileName.substring(ii,sLocalFileName.length());
//得到不重复的文件名
java.util.Date dt = new java.util.Date(System.currentTimeMillis());
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
sServerFileName= fmt.format(dt);
sServerFileName =sServerFileName + sExt;
//如果不存在该目录,则新建一个
File dir =new File(sPath);
if (!dir.exists()){
dir.mkdirs();
}
upBean.setFolderstore(sPath);//设置要上传的目录
upBean.addUploadListener(fileMover);//增加filMover监听
fileMover.setNewfilename(sServerFileName);//设置服务器上的文件名
upBean.store(mrequest, "attach");//上传
out.println("file path is "+sPath+"/"+sServerFileName);
}%>
[/code]
<tr><td>廣告路徑:
<input type="file" name="myFile" id="advertPath">
</td></tr>action中定义这些属性,并提供set,get方法,此处省略
private File myFile;
private String myFileFileName;
private TblAdvert tblAdvert;
private String fileName;public void setMyFileFileName(String fileName) {
System.out.println("myFileFileName為:"+myFileFileName);
this.myFileFileName = fileName;
}
private static void copy(File src, File dst) {
try {
InputStream in = null ;
OutputStream out = null ;
try {
in = new BufferedInputStream( new FileInputStream(src), 16 * 1024);
out = new BufferedOutputStream( new FileOutputStream(dst), 16 * 1024);
byte [] buffer = new byte [16 * 1024];
while (in.read(buffer) > 0 ) {
out.write(buffer);
}
} finally {
if ( null != in) {
in.close();
}
if ( null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public String addposter(){
System.out.println("進入到增加方法里了");
int pos = myFileFileName.lastIndexOf(".");
fileName = new Date().getTime()+ myFileFileName.substring(pos);
File dst = new File(ServletActionContext.getServletContext().getRealPath("/UploadImages" ) + "/" + fileName);
copy(myFile, dst);
tblAdvert.setAdvertPath(fileName);
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
try {
session.save(tblAdvert);
tx.commit();
System.out.println("save success");
} catch (Exception e) {
tx.rollback();
e.printStackTrace();
}finally{
session.close();
}
return "addposterOk";
}
按道理来说,上传必须是客户端发启的。不然你代码中写个文件路径,想要什么文件就能偷什么文件了。
但是这个不是我想要的
我现在的问题是
我用二代身份证扫描机扫描身份证(一扫描身份证就得把图片上传到服务器去)
身份证信息显示到文本框里去
这个都没问题
然后它会自动生成一张图片,就是身份证上面的头像默认在C盘
怎么把c盘的图片上传到我的服务器中
不是点浏览,没有用到这个<input type="file">
而是
<input type="text" value="图片的绝对路径">
是客户端的路径,打个比方,比如说你D盘的图片,d:\a.jpg
<input type="text" value="d:\a.jpg">
jsp页面文本框就是现实你d盘图片
有没有办法上传到我服务器上
只通过浏览器基本没可能实现这上传的功能的。我是不知道。
Xproer.HttpUploader:http://www.cnblogs.com/xproer/archive/2010/10/24/1859895.html
此控件是基于标准HTTP协议实现的文件上传功能。优势是扩展性非常好,整合简单,支持批量上传文件和上传文件夹功能,适合各种简单WEB项目。
另外一个特点是支持自动上传指定的本地文件。单文件上传演示上传本地文件代码
使用步骤如下:
1.调用AddFile函数添加本地文件,注意路径需要使用双斜框(\\)
2.调用PostFirst函数开始上传文件。<script type="text/javascript" language="javascript">
var uploaderMgr = new HttpUploaderMgr();
uploaderMgr.Load();//加载控件 window.onload = function()
{
uploaderMgr.Init();//初始化控件
//添加一个本地文件
uploaderMgr.AddFile("D:\\Soft\\QQ2010.exe");
uploaderMgr.PostFirst(); };
</script>
单文件整合代码: 服务器返回消息:<input id="txtFilePath" type="text" size="50" />
<script type="text/javascript" language="javascript">
var uploaderMgr = new HttpUploaderSingleMgr();
uploaderMgr.Config["PostUrl"] = "http://localhost:8080/asp.net/upload.aspx";
uploaderMgr.Load();
//文件上传完成后执行的回调函数
uploaderMgr.CompleteHook = function(msg)
{
document.getElementById("txtFilePath").value = msg;
}; window.onload = function()
{
uploaderMgr.Init();
};
</script>
这个用到了OCX,但是OCX没办法上传
你这样弄几下就把我电脑上的文件给传到了服务器,
NND,哥的私生活全都要曝光了
var uploaderMgr = new HttpUploaderMgr();
uploaderMgr.Load();//加载控件 window.onload = function()
{
uploaderMgr.Init();//初始化控件
//添加一个本地文件,在这里指定本地文件的路径。
uploaderMgr.AddFile("D:\\Soft\\QQ2010.exe");
uploaderMgr.PostFirst(); };
</script>
如果不想花钱的话,用commons-fileupload-1.1.1.jar也不错
现在我服务器在北京
你人在广州可以通过外网访问系统
然后你有个身份证扫描器,一扫描身份证,可以把信息都显示到jsp
<input type="text" value="张三>
<input type="text" value="男">等等
当然这些value都是通过OCX来获取的
同时这个身份证扫描机会在你自己的机子上生成一个图片,就是你身份证上面的头像,默认保存路劲
C:\Program Files\Internet Explorer\tmp.bmp
这个也可以扫描到jsp去
<input type="text" value="C:\Program Files\Internet Explorer\tmp.bmp">就类似这样
但是这只是一个绝对地址,我怎么上传到我服务器?