jsp中使用jquery的ajaxfileupload插件怎么实现异步上传
2015-01-12 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517181
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
<script type=text/javascript src=js/jquery.js</script
<script type=text/javascript src=js/ajaxfileupload.js</script
<!-- 执行上传文件操作的函数 --
<script type=text/javascript
function ajaxFileUpload(){
$.ajaxFileUpload({url:'update.do?method=uploader', //需要链接到服务器地址
secureuri:false,
fileElementId:'houseMaps', //文件选择框的id属性
dataType: 'xml', //服务器返回的格式,可以是json
success: function (data, status) //相当于java中try语句块的用法{$('#result').html('添加成功');},
error: function (data, status, e) //相当于java中catch语句块的用法{$('#result').html('添加失败');}});}</script</head<body<form method=post action=update.do?method=uploader enctype=multipart/form-data
<input type=file id=houseMaps name=houseMaps/
<input type=button value=提交 onclick=ajaxFileUpload()/</form<div id=result</div</body</html服务器代码:
public class UpdateAction extends DispatchAction {
public ActionForward uploader(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UpFormForm upFormForm = (UpFormForm) form;
FormFile ff = upFormForm.getHouseMaps();try {InputStream is = ff.getInputStream();
File file = new File(D:/ + ff.getFileName()); //指定文件存储的路径和文件名
OutputStream os = new FileOutputStream(file);
byte[] b = new byte[1024];
int len = 0;
while((len = is.read(b)) != -1){
os.write(b, 0, len);}os.close();
is.close();
} catch (Exception e) {
<script type=text/javascript src=js/ajaxfileupload.js</script
<!-- 执行上传文件操作的函数 --
<script type=text/javascript
function ajaxFileUpload(){
$.ajaxFileUpload({url:'update.do?method=uploader', //需要链接到服务器地址
secureuri:false,
fileElementId:'houseMaps', //文件选择框的id属性
dataType: 'xml', //服务器返回的格式,可以是json
success: function (data, status) //相当于java中try语句块的用法{$('#result').html('添加成功');},
error: function (data, status, e) //相当于java中catch语句块的用法{$('#result').html('添加失败');}});}</script</head<body<form method=post action=update.do?method=uploader enctype=multipart/form-data
<input type=file id=houseMaps name=houseMaps/
<input type=button value=提交 onclick=ajaxFileUpload()/</form<div id=result</div</body</html服务器代码:
public class UpdateAction extends DispatchAction {
public ActionForward uploader(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UpFormForm upFormForm = (UpFormForm) form;
FormFile ff = upFormForm.getHouseMaps();try {InputStream is = ff.getInputStream();
File file = new File(D:/ + ff.getFileName()); //指定文件存储的路径和文件名
OutputStream os = new FileOutputStream(file);
byte[] b = new byte[1024];
int len = 0;
while((len = is.read(b)) != -1){
os.write(b, 0, len);}os.close();
is.close();
} catch (Exception e) {
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询