multipart/form-data编码中有对应上传文件的项:
boundary
Content-Disposition: form-data; name="file"; filename="yourfilename"
Content-Type.....
boundary
Content-Disposition: form-data; name="file"; filename="yourfilename"
Content-Type.....
解决方案 »
- 请教一个简单的js代码调试问题
- 关于简单的spring3.x的自动装载autowire
- 求助求助!http://localhost:8080/axis2/services/HelloWorldService 无法显示
- 数据库连接池的运行机制是什么?
- 怎么在Struts中取得浏览器所用的协议?JSP中哪个对象包含了与协议有关的东东?
- 关于SPRING的一个问题
- 我的数据库这是怎么了(SQL server2000+tomcat5+jdk1.4.2)
- 什末时候该关闭session?
- 50分....求达人帮忙,写出服务器监听8080端口接收客户端信息过程!!!!!!!!!!!!!!!!!
- 大家讨论:你们梦想中希望开发个什么系统,有创意者高分!100分!
- ***散分问路--各位高手进来看看--言者有分!!!--关于多层CS开发有没有市场???
- 怎样把JBoss作为一个服务启动?
Hashtable files=mreq.getFiles();
if((files!=null)||(!files.isEmpty())){
CosUploadFile file=(CosUploadFile)files.get("file_name");
........
}}
Content-Disposition: form-data; name="file"; filename="FileName"Content-Type.....
你在servlet中将输入流读出,获取filename后的字符,就可以得到
"C:/path/FileName"或者"FileName"的字符串(操作系统不同),这样,最后一个“/”后面的就是文件名,
<%@ page language="java" %>
<%@ page contentType="text/html;charset=gb2312" %>
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<%@ include file="../DSS/s1dss.ini" %>
<%@ page import = "com.jspsmart.upload.*,java.io.File,java.lang.String" %>
<jsp:useBean id="fileUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/><%
String ptype = request.getParameter("ptype");
String prow = request.getParameter("prow"); String filename = "";
// Variables
int count=0; // Initialization
fileUpload.initialize(pageContext); fileUpload.setTotalMaxFileSize(maxfile); try{
fileUpload.upload();
filename = fileUpload.getFiles().getFile(count).getFileName();
String newpath = uploadpath + "/" + filename;
String urlval = request.getRequestURL().toString();
String path = request.getServletPath();
String domainname = urlval.replaceAll(path, newpath);
domainname = new String(domainname.trim().getBytes(), "GB2312");
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 = fileUpload.save(uploadpath);
} catch (Exception e) {
out.println(e.toString());
}
out.println("<script language='javascript'>");
out.println("window.opener.frmInput.url.value = '" + domainname + "';");
out.println("alert('文件上载完毕!')");
out.println("window.close();");
out.println("</script>");
}
catch(SecurityException se){
out.println("<script language='javascript'>");
out.println("document.location.href = 'reselect.jsp?ptype=" + ptype + "&prow=" + prow + "';");
out.println("</script>");
}
%>
在文件中一定会有,Content-Disposition: form-data; name="file"; filename="FileName"这样的字符串(可通过getContentType() 得到),取FileName 就可以了,