<% String path = request.getContextPat,咨信网zixin.com.cn" /> <% String path = r"/>
收藏 分销(赏)

uploadify_java.doc

上传人:xrp****65 文档编号:7660021 上传时间:2025-01-11 格式:DOC 页数:5 大小:28KB 下载积分:10 金币
下载 相关 举报
uploadify_java.doc_第1页
第1页 / 共5页
uploadify_java.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
1. jsp的内容 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>兑换卷查询系统</title> <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" /> <link href="css/uploadify.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="js/jquery.uploadify-3.1.min.js"></script> </head> <style> </style> <body> <form> <div id="fileQueue"></div> <h4>提货券类型</h4> <input type="radio" id="typeCode" name="typeCode" value="108" checked="">108</input> <input type="radio" id="typeCode" name="typeCode" value="138">138</input> </p> <input type="file" name="file_upload" id="file_upload" /> <p> <a href="javascript:$('#file_upload').uploadify('upload','*')">开始上传</a> <script> $(function() { var typeCode =""; $("#file_upload").uploadify({ 'buttonText' : '选择文件', 'multi' : false, 'swf' : 'html/uploadify.swf', 'uploader' : '../servlet/Upload', 'auto' : false, 'onUploadStart' : function(file) { //校验 $(":input[name='typeCode']").each(function(){ if ( $(this).attr("checked")) { typeCode = ($(this).val()); } }); $("#file_upload").uploadify("settings", "formData", {'typeCode':typeCode}); } }); }); </script> </p> <!-- <a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">取消所有上传</a> --> </p> </form> </body> </html> 2.java服务器端的程序 package com.alcor.inquire.servlet; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.UUID; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.tomcat.util.http.fileupload.FileItem; import org.apache.tomcat.util.http.fileupload.FileUploadException; import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory; import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; public class ImportData extends HttpServlet { /** * */ private static final long serialVersionUID = 3387249060639006401L; private static final Logger logger = Logger.getLogger(ImportData.class); public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("doGet(HttpServletRequest request, HttpServletResponse response)"); String typeCode =""; //兑换卷类型 String savePath = this.getServletConfig().getServletContext().getRealPath(""); savePath = savePath + "/uploads/"; File f1 = new File(savePath); System.out.println(savePath); if (!f1.exists()) { f1.mkdirs(); } DiskFileItemFactory fac = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(fac); upload.setHeaderEncoding("utf-8"); List<FileItem> fileList = null; try { fileList = upload.parseRequest(request); } catch (FileUploadException ex) { return; } Iterator<FileItem> it = fileList.iterator(); String name = ""; String extName = ""; while (it.hasNext()) { FileItem item = it.next(); logger.debug(item.getContentType()); if (!item.isFormField()) { name = item.getName(); long size = item.getSize(); String type = item.getContentType(); logger.debug("文件名:"+name+",大小:"+size + ",类型:" + type); if (name == null || name.trim().equals("")) { continue; } //扩展名格式: if (name.lastIndexOf(".") >= 0) { extName = name.substring(name.lastIndexOf(".")); } File file = null; do { //生成文件名: name = UUID.randomUUID().toString(); file = new File(savePath + name + extName); } while (file.exists()); File saveFile = new File(savePath + name + extName); try { item.write(saveFile); } catch (Exception e) { e.printStackTrace(); } }else { //获得简单域的名字 String fieldName = item.getFieldName(); if (fieldName.equalsIgnoreCase("typeCode")) { //获得简单域的值 String fieldValue = item.getString("UTF-8"); typeCode = fieldValue; logger.debug("兑换卷类型是:"+typeCode); } } } response.getWriter().print(name + extName); } // Process the HTTP Post request public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } 3.jsp代码中 如下代码是关键,否则服务端无法获取radio的值 $("#file_upload").uploadify("settings", "formData", {'typeCode':typeCode});
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服