- 浏览: 242840 次
- 性别:
- 来自: 四川
文章分类
最新评论
-
coosummer:
推荐使用http://buttoncssgenerator.c ...
Button CSS 样式 -
tangshengpan:
楼主,我跟你的情况一样,有现成OCX控件,用JAVA调用,出错 ...
Java调用OCX的方法(已存在OCX) -
bushkarl:
恩,思路挺清晰的
oracle 如何解决表间大数据量的复制select into table1 from table2 -
baixiaozhe:
确实不错! 我曾用scroll实现过类似效果
flex中实现marquee效果(由下而上滚动) -
sosyi:
我的报这样的错:
Exception in thread &q ...
Java调用OCX的方法(已存在OCX)
Java代码
internal function init():void{
Security.allowDomain("*");
file = new FileReference();
file.addEventListener(Event.SELECT, onSelect);
file.addEventListener(ProgressEvent.PROGRESS, processHandler);
file.addEventListener(IOErrorEvent.IO_ERROR,ioShow);
}
internal function ioShow(evt: IOErrorEvent){
Alert.show(evt.toString(),"IO错误");
}
internal function doSelect():void{
//文件类型限制,第一个是文件类型选项只显示"png"类型的,第二个是只把.png文件显示出来
var imageTypes:FileFilter = new FileFilter("png", "*.png");
var allTypes:Array = new Array(imageTypes);
file.browse(allTypes);
}
internal function onSelect(evt:Event):void{
pic_txt.text = file.name;
}
internal function doUpload():void{
//指向struts的一个action,或servlte,注意一写要写完整路径
var request:URLRequest = new URLRequest("http://localhost:8080/productManage/uploadPic.do");
fileName = "productImage\\"+new Date().getTime().toString() +".png";
request.data = new URLVariables("filename="+fileName);
file.upload(request);
CursorManager.setBusyCursor();
}
//上传完成更新源
internal function processHandler(evt:ProgressEvent):void{
if(evt.bytesLoaded == evt.bytesTotal){
CursorManager.removeBusyCursor();
var n:Number = new Date().getTime();
img.source = fileName +"?time="+n;
}
}
<mx:TextInput id="pic_txt" width="150"/>
<mx:Button label="选择文件" click="doSelect()"/>
<mx:Button label="开始上传" click="doUpload()"/>
internal function init():void{
Security.allowDomain("*");
file = new FileReference();
file.addEventListener(Event.SELECT, onSelect);
file.addEventListener(ProgressEvent.PROGRESS, processHandler);
file.addEventListener(IOErrorEvent.IO_ERROR,ioShow);
}
internal function ioShow(evt: IOErrorEvent){
Alert.show(evt.toString(),"IO错误");
}
internal function doSelect():void{
//文件类型限制,第一个是文件类型选项只显示"png"类型的,第二个是只把.png文件显示出来
var imageTypes:FileFilter = new FileFilter("png", "*.png");
var allTypes:Array = new Array(imageTypes);
file.browse(allTypes);
}
internal function onSelect(evt:Event):void{
pic_txt.text = file.name;
}
internal function doUpload():void{
//指向struts的一个action,或servlte,注意一写要写完整路径
var request:URLRequest = new URLRequest("http://localhost:8080/productManage/uploadPic.do");
fileName = "productImage\\"+new Date().getTime().toString() +".png";
request.data = new URLVariables("filename="+fileName);
file.upload(request);
CursorManager.setBusyCursor();
}
//上传完成更新源
internal function processHandler(evt:ProgressEvent):void{
if(evt.bytesLoaded == evt.bytesTotal){
CursorManager.removeBusyCursor();
var n:Number = new Date().getTime();
img.source = fileName +"?time="+n;
}
}
<mx:TextInput id="pic_txt" width="150"/>
<mx:Button label="选择文件" click="doSelect()"/>
<mx:Button label="开始上传" click="doUpload()"/>
java端:
Java代码
import java.io.File;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class UploadPicAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/html; charset=UTF-8");
DiskFileUpload upload = new DiskFileUpload();
try {
List itemlist = upload.parseRequest(request);
//itemlist里包含多个参数,所以要判断一下是文件类型,还是参数字段,这里修改一下可以用于多个文件上传
for (int i = 0; i < itemlist.size(); i++) {
FileItem item = (FileItem) itemlist.get(i);
if (item.isFormField())//是表单字段跳过
continue;
String name = request.getRealPath("") + "\\bin\\"
+ request.getParameter("filename");//获得Web应用绝对路径,如果路径不在web应用下,由于安全机制,将会说"找不到系统指定路径"
try {
File f = new File(name);
item.write(f);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (FileUploadException e) {
e.printStackTrace();
}
return null;
}
}
FLEX带进度指示的文件上传
无意百度到一个示例代码,贴出来。
FileUploadServlet.java源码:
package com.fire.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class FileUploadServlet extends HttpServlet {
// 定义文件的上传路径
private String uploadPath = "D:\\upload\\";
// 限制文件的上传大小
private int maxPostSize = 100 * 1024 * 1024;
public FileUploadServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//得到用户需要保存的服装的id
String dressId = request.getParameter("dressID");
System.out.println(dressId);
//保存文件到服务器中
response.setContentType("text/html; charset=UTF-8");
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(maxPostSize);
try
{
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (!item.isFormField())
{
String name = item.getName();
System.out.println(name);
try
{
item.write(new File(uploadPath + name));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
catch (FileUploadException e)
{
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
public void init() throws ServletException {
// Put your code here
}
}
fileupload.mxml源码:
<mx:application xmlns="*" layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml" creationcomplete="init();"> </mx:application>
xml 代码
xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns="*" creationComplete="init();">
<mx:Script>
import flash.net.FileReference;
import mx.controls.Alert;
import mx.events.CloseEvent;
import flash.events.*;
private var file: FileReference;
private function init(): void{
Security.allowDomain("*");
file = new FileReference();
file.addEventListener(ProgressEvent.PROGRESS, onProgress);
file.addEventListener(Event.SELECT, onSelect);
}
private function upload(): void{
file.browse();
}
private function onSelect(e: Event): void{
Alert.show("上传 " + file.name + " (共 "+Math.round(file.size)+" 字节)?",
"确认上传",
Alert.YES|Alert.NO,
null,
proceedWithUpload);
}
private function onProgress(e: ProgressEvent): void{
lbProgress.text = " 已上传 " + e.bytesLoaded
+ " 字节,共 " + e.bytesTotal + " 字节";
var proc: uint = e.bytesLoaded / e.bytesTotal * 100;
bar.setProgress(proc, 100);
bar.label= "当前进度: " + " " + proc + "%";
}
private function proceedWithUpload(e: CloseEvent): void{
if (e.detail == Alert.YES){
var request: URLRequest = new URLRequest("http://localhost:8080/dress/fileUploadServlet");
try {
file.upload(request);
} catch (error:Error) {
trace("上传失败");
}
}
}
]]>
mx:Script>
<mx:Canvas width="100%" height="100%">
<mx:VBox width="100%" horizontalAlign="center">
<mx:Label id="lbProgress" text="上传"/>
<mx:ProgressBar id="bar" labelPlacement="bottom" themeColor="#F20D7A"
minimum="0" visible="true" maximum="100" label="当前进度: 0%"
direction="right" mode="manual" width="200"/>
<mx:Button label="上传文件" click="upload();"/>
mx:VBox>
mx:Canvas>
mx:Application>
internal function init():void{
Security.allowDomain("*");
file = new FileReference();
file.addEventListener(Event.SELECT, onSelect);
file.addEventListener(ProgressEvent.PROGRESS, processHandler);
file.addEventListener(IOErrorEvent.IO_ERROR,ioShow);
}
internal function ioShow(evt: IOErrorEvent){
Alert.show(evt.toString(),"IO错误");
}
internal function doSelect():void{
//文件类型限制,第一个是文件类型选项只显示"png"类型的,第二个是只把.png文件显示出来
var imageTypes:FileFilter = new FileFilter("png", "*.png");
var allTypes:Array = new Array(imageTypes);
file.browse(allTypes);
}
internal function onSelect(evt:Event):void{
pic_txt.text = file.name;
}
internal function doUpload():void{
//指向struts的一个action,或servlte,注意一写要写完整路径
var request:URLRequest = new URLRequest("http://localhost:8080/productManage/uploadPic.do");
fileName = "productImage\\"+new Date().getTime().toString() +".png";
request.data = new URLVariables("filename="+fileName);
file.upload(request);
CursorManager.setBusyCursor();
}
//上传完成更新源
internal function processHandler(evt:ProgressEvent):void{
if(evt.bytesLoaded == evt.bytesTotal){
CursorManager.removeBusyCursor();
var n:Number = new Date().getTime();
img.source = fileName +"?time="+n;
}
}
<mx:TextInput id="pic_txt" width="150"/>
<mx:Button label="选择文件" click="doSelect()"/>
<mx:Button label="开始上传" click="doUpload()"/>
internal function init():void{
Security.allowDomain("*");
file = new FileReference();
file.addEventListener(Event.SELECT, onSelect);
file.addEventListener(ProgressEvent.PROGRESS, processHandler);
file.addEventListener(IOErrorEvent.IO_ERROR,ioShow);
}
internal function ioShow(evt: IOErrorEvent){
Alert.show(evt.toString(),"IO错误");
}
internal function doSelect():void{
//文件类型限制,第一个是文件类型选项只显示"png"类型的,第二个是只把.png文件显示出来
var imageTypes:FileFilter = new FileFilter("png", "*.png");
var allTypes:Array = new Array(imageTypes);
file.browse(allTypes);
}
internal function onSelect(evt:Event):void{
pic_txt.text = file.name;
}
internal function doUpload():void{
//指向struts的一个action,或servlte,注意一写要写完整路径
var request:URLRequest = new URLRequest("http://localhost:8080/productManage/uploadPic.do");
fileName = "productImage\\"+new Date().getTime().toString() +".png";
request.data = new URLVariables("filename="+fileName);
file.upload(request);
CursorManager.setBusyCursor();
}
//上传完成更新源
internal function processHandler(evt:ProgressEvent):void{
if(evt.bytesLoaded == evt.bytesTotal){
CursorManager.removeBusyCursor();
var n:Number = new Date().getTime();
img.source = fileName +"?time="+n;
}
}
<mx:TextInput id="pic_txt" width="150"/>
<mx:Button label="选择文件" click="doSelect()"/>
<mx:Button label="开始上传" click="doUpload()"/>
java端:
Java代码
import java.io.File;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class UploadPicAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/html; charset=UTF-8");
DiskFileUpload upload = new DiskFileUpload();
try {
List itemlist = upload.parseRequest(request);
//itemlist里包含多个参数,所以要判断一下是文件类型,还是参数字段,这里修改一下可以用于多个文件上传
for (int i = 0; i < itemlist.size(); i++) {
FileItem item = (FileItem) itemlist.get(i);
if (item.isFormField())//是表单字段跳过
continue;
String name = request.getRealPath("") + "\\bin\\"
+ request.getParameter("filename");//获得Web应用绝对路径,如果路径不在web应用下,由于安全机制,将会说"找不到系统指定路径"
try {
File f = new File(name);
item.write(f);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (FileUploadException e) {
e.printStackTrace();
}
return null;
}
}
FLEX带进度指示的文件上传
无意百度到一个示例代码,贴出来。
FileUploadServlet.java源码:
package com.fire.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class FileUploadServlet extends HttpServlet {
// 定义文件的上传路径
private String uploadPath = "D:\\upload\\";
// 限制文件的上传大小
private int maxPostSize = 100 * 1024 * 1024;
public FileUploadServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//得到用户需要保存的服装的id
String dressId = request.getParameter("dressID");
System.out.println(dressId);
//保存文件到服务器中
response.setContentType("text/html; charset=UTF-8");
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(maxPostSize);
try
{
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (!item.isFormField())
{
String name = item.getName();
System.out.println(name);
try
{
item.write(new File(uploadPath + name));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
catch (FileUploadException e)
{
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
public void init() throws ServletException {
// Put your code here
}
}
fileupload.mxml源码:
<mx:application xmlns="*" layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml" creationcomplete="init();"> </mx:application>
xml 代码
xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns="*" creationComplete="init();">
<mx:Script>
import flash.net.FileReference;
import mx.controls.Alert;
import mx.events.CloseEvent;
import flash.events.*;
private var file: FileReference;
private function init(): void{
Security.allowDomain("*");
file = new FileReference();
file.addEventListener(ProgressEvent.PROGRESS, onProgress);
file.addEventListener(Event.SELECT, onSelect);
}
private function upload(): void{
file.browse();
}
private function onSelect(e: Event): void{
Alert.show("上传 " + file.name + " (共 "+Math.round(file.size)+" 字节)?",
"确认上传",
Alert.YES|Alert.NO,
null,
proceedWithUpload);
}
private function onProgress(e: ProgressEvent): void{
lbProgress.text = " 已上传 " + e.bytesLoaded
+ " 字节,共 " + e.bytesTotal + " 字节";
var proc: uint = e.bytesLoaded / e.bytesTotal * 100;
bar.setProgress(proc, 100);
bar.label= "当前进度: " + " " + proc + "%";
}
private function proceedWithUpload(e: CloseEvent): void{
if (e.detail == Alert.YES){
var request: URLRequest = new URLRequest("http://localhost:8080/dress/fileUploadServlet");
try {
file.upload(request);
} catch (error:Error) {
trace("上传失败");
}
}
}
]]>
mx:Script>
<mx:Canvas width="100%" height="100%">
<mx:VBox width="100%" horizontalAlign="center">
<mx:Label id="lbProgress" text="上传"/>
<mx:ProgressBar id="bar" labelPlacement="bottom" themeColor="#F20D7A"
minimum="0" visible="true" maximum="100" label="当前进度: 0%"
direction="right" mode="manual" width="200"/>
<mx:Button label="上传文件" click="upload();"/>
mx:VBox>
mx:Canvas>
mx:Application>
发表评论
-
FLEX带进度指示的文件上传
2010-04-03 15:56 1061转载: http://tj007-bo.iteye.com/b ... -
air+ajax
2009-12-27 13:06 701http://fins.iteye.com/blog/5561 ... -
主题:flex设计表格的复杂表头(类似报表的斜线表头)
2009-07-19 11:48 2816http://www.iteye.com/topic/3802 ... -
flex datagrid 自定义
2009-07-11 03:13 1288http://blog.csdn.net/heimaoxiao ... -
flex 中使用xml文件
2009-07-11 02:59 771<artwork> <piec ... -
介绍开源Flash游戏引擎PushButton Engine
2009-07-10 22:54 3673介绍开源Flash游戏引擎PushButton Engine ... -
Flex 最佳做法(初学者)文件命名与注意事项
2009-07-10 13:39 852转载于:http://www.adobe.com/cn/dev ... -
puremvc flex 简单例子
2009-07-09 23:07 1350puremvc flex 简单例子 http://wmc ... -
一个不错的Flex效果(一个会转动的3D盒子的效)
2009-07-09 11:10 930转载于: http://www.blogjava.net/cp ... -
一款flex操作系统
2009-07-08 09:30 829http://ijimu.cn/ -
Flex组件的项目渲染器(ItemRenderer)使用
2009-07-04 23:34 721http://blog.csdn.net/babylon_00 ... -
给Flex的PopUpManager显示控件添加特效
2009-07-04 20:11 2498PopUpManager本身不提供显示控件特效设置,对控件的s ... -
Flex上传文件功能
2009-07-03 10:31 3894Flex代码 <?xml version=" ... -
Flex使用弹出窗口为DataGrid添加新数据
2009-07-02 20:03 942经常在Demo中会看到列表,表格等方式来显示数据。当然有时候也 ...
相关推荐
Apache Commons Math 3.6.1 是一个由Apache软件基金会开发的开源库,它提供了广泛的数学和统计功能,适用于各种编程任务。这个版本是3.6.1,意味着它是对之前版本的改进和增强,可能包括错误修复、性能优化以及新...
报道了MMONS的生长,研究了它的二阶非线性光学性能,为MMONS能实际应用提供了理论指导。
目前,仅Firestore扩展可用。 安装方式 npm install git://github.com/co-mmons/firebase-js-utils.git 入门 加载扩展: import {FirestoreHelper} "@co.... import "@co.mmons/firebase-js-utils/firestore/rxjs
Donald Brown,Atlassian软件系统公司托管服务的首席软件工程师和Apache软件基金会成员,参与开发了Slruts及多个ApacheC0mmons项目,并且是JavaOne、ApacheCon和Java用户组的活跃分子。 Chad Michael Davis,J2EE...
Donald Brown,Atlassian软件系统公司托管服务的首席软件工程师和Apache软件基金会成员,参与开发了Slruts及多个ApacheC0mmons项目,并且是JavaOne、ApacheCon和Java用户组的活跃分子。 Chad Michael Davis,J2EE...