jsp+Ext2.0实现的文件上传功能
来源:互联网 发布:域名dns污染怎么解决 编辑:程序博客网 时间:2024/04/30 04:34
html代码:
<input type="button" class="x-btn" onclick="uploadFile()" id="upFileBtn" value=" 上传文件 ">
<div id="upFile-dlg" class="x-hidden">
<div class="x-window-header">
</div>
<div class="x-window-body">
<form method="POST" action="" name="form2" enctype="multipart/form-data">
<table align="center">
<tr class="x-form-item">
<td>请选择需要上传的文件: </td>
</tr>
<tr class="x-form-item">
<td>
<input type="file" name="fileUp" id='fileUp' class="mandatory" style="width:340px;" />
</td>
</tr>
</table>
</form>
</div>
</div>
js代码:
uploadForm = new Ext.form.BasicForm('form2');
var fileUp = new Ext.form.TextField( {
applyTo:'fileUp',
id : 'fileUp',
allowBlank : false,
width : 340
});
uploadForm.add(fileUp);
var upLoadDlg;
function uploadFile()
{
if(upLoadDlg == null)
{
upLoadDlg = new Ext.Window(
{
el:'upFile-dlg',
width:370,
height:100,
modal:true,
closeAction:'hide',
resizable: false,
plain: true,
buttons: [
{
text: "上传",
handler: uploadfile
},{
text: '取消',
handler: function(){
upLoadDlg.hide();
}
}]
});
}
upLoadDlg.show(Ext.get('upFileBtn').dom);
}
function uploadfile()
{
var fileValue = Ext.get('fileUp').dom.value;
if(uploadForm.isValid())
{
upLoadDlg.hide();
uploadForm.doAction('submit', {
url : "casefileUpload.jsp?caseId="+ caseId + "&fileValue=" + fileValue,
method : 'post'
});
}else
{
Ext.MessageBox.alert("提示","请选择需要上传的文件!");
}
}
jsp文件:(主要用到一个上传文件的包:commons-fileupload-1.2.jar)
<%
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
%>
<%@ page contentType="text/html; charset=GB2312"%>
<%@ page import="org.apache.commons.logging.Log"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="com.nanwang.gebss.casedeal.CaseMaterialService"%>
<%@ page import="com.nanwang.gebss.db.CaseMaterial"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%
if (request.getMethod().equalsIgnoreCase("get"))
{
}
else
{
String caseId = request.getParameter("caseId");
java.util.HashMap parameters = new java.util.HashMap();
DiskFileUpload fu = new DiskFileUpload();
// maximum size before a FileUploadException will be thrown
fu.setSizeMax(100000000);
// maximum size that will be stored in memory
fu.setSizeThreshold(4096000);
// the location for saving data that is larger than getSizeThreshold()
fu.setRepositoryPath(application.getRealPath("/WEB-INF/"));
java.util.List fileItems = fu.parseRequest(request);
// assume we know there are two files. The first file is a small
// text file, the second is unknown and is written to a file on
// the server
for (java.util.Iterator it = fileItems.iterator(); it.hasNext();)
{
FileItem fileItem = (FileItem) it.next();
if (fileItem.isFormField())
{
String value = null;
value = fileItem.getString(request.getCharacterEncoding());
parameters.put(fileItem.getFieldName(), value);
}
else
{
String comment = fileItem.getString();
// filename on the client
String fileName = fileItem.getName();
// save comment and filename to database
//...
// write the file
int i = 0;
if (fileItem.getSize() > 0 && fileName != null
&& fileName.length() > 0)
{
i = fileName.lastIndexOf('//');
System.out.println(new java.io.File(application
.getRealPath("//photo")
+ "//" + fileName.substring(i + 1)).getAbsolutePath());
fileItem.write(new java.io.File(application.getRealPath("//photo")
+ "//" + fileName.substring(i + 1)));
CaseMaterial caseMaterial = new CaseMaterial();
caseMaterial.setCaseId(String.valueOf(caseId));
caseMaterial.setMaterialType("图片");
caseMaterial.setSource("web");
caseMaterial.setStoreKey(fileName.substring(i + 1));
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr=sdf.format(dt);
caseMaterial.setMemo(dateStr);
CaseMaterialService caseMatSer = new CaseMaterialService();
caseMatSer.insertCaseMaterial(caseMaterial);
}
}
}
}
%>
- jsp+Ext2.0实现的文件上传功能
- jsp+servlet实现文件的上传功能
- ext2.0文件上传
- JSP + Servlet 实现的文件上传到服务器的功能
- Servlet+Jsp实现图片或文件的上传功能
- ext2.0+java 文件上传
- ext2.0+java 文件上传
- Jsp+Servlet文件上传功能实现
- 【已解决】Jsp实现文件上传功能
- 文件上传功能的实现
- 文件上传功能的实现
- 文件上传功能的实现
- 文件上传功能的实现
- 文件上传功能的实现
- 2007.5.15-----如何用jsp实现文件上传功能?
- SSH,JSP用FormFile实现文件上传功能
- (jsp和Servlet 功能篇) Servlet 实现文件上传
- 理论---jsp使用jspsmartupload组件实现文件上传功能
- 世界编程大赛第一名写的程序
- 交叉编译场景分析(Arm-Linux)
- 利用BeanUtils在对象间复制属性
- iframe如何获得父页面的值
- 华为薪酬[转]
- jsp+Ext2.0实现的文件上传功能
- c#实现ftp功能
- 软盘结构(磁头号和起始扇区的计算方法)
- 代理模式实例
- 常用js方法
- BubbleSort
- hdu/hdoj 1215-七夕节
- 我们为什么要使用linux
- 用命令行启动和停止iis、sql server