`
soleegn
  • 浏览: 147558 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论
阅读更多

I impleted my File upload/download system with rap internal Browser + servlet.
upload dialog:

public class FileUploadDialog extends TitleAreaDialog {
	private Browser browser;
	public FileUploadDialog(Shell parentShell) {
		super(parentShell);
	}
	/**
	 * Create contents of the dialog
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite area = (Composite) super.createDialogArea(parent);
		Composite container = new Composite(area, SWT.NONE);
		container.setLayout(new FillLayout());
		container.setLayoutData(new GridData(GridData.FILL_BOTH));

browser = new Browser(container, SWT.NONE);
String url = "http://"+RWT.getRequest().getServerName()+":"+RWT.getRequest().getServerPort()+"/web/fileupload.jsp";
String html = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><html><head><title>upload file</title></head><body>"+
"<form action=\""+url+"\" enctype=\"MULTIPART/FORM-DATA\" method=\"post\"><br />File Name:</br><input type=\"file\""+
" name=\"filename\"/><br><input type=\"submit\" value=\"upload\"/></form></body></html> ";
browser.setText(html);
setMessage("select a local file");
return area;
}
	/**
	 * Return the initial size of the dialog
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(382, 280);
	}
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("upload file");
	}
}

file upload sevlet:
public class FileUploadServlet extends HttpServlet {
	private static final long serialVersionUID = -7245361228773015964L;
	private String uploadPath = "/upload/"; // server file repository
	private String tempPath = "/upload/tmp/"; //temp file folder

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
DiskFileUpload fu = new DiskFileUpload();
// max file size fu.setSizeMax(-1);
// buffer size
fu.setSizeThreshold(4096);
// temp path
fu.setRepositoryPath(tempPath);
			// get all uploa file
			List fileItems = fu.parseRequest(request);
			Iterator i = fileItems.iterator();
			while (i.hasNext()) {
				FileItem fi = (FileItem) i.next();
				// get the upload file name
				String fileName = fi.getName();
				String sep = System.getProperty("file.separator");
				int index = fileName.lastIndexOf(sep);
				if(index >-1){
					fileName = fileName.substring(fileName.lastIndexOf(sep));
				}
				fi.write(new File(uploadPath + fileName));
				response.getWriter().println(fileName+"upload success");
			}
		} catch (Exception e) {
		 //do something?
			e.printStackTrace();
		}
	}
	public void init() throws ServletException {
		if (!new File(uploadPath).isDirectory())
			new File(uploadPath).mkdirs();
		if (!new File(tempPath).isDirectory())
			new File(tempPath).mkdirs();
	}
}
registe servlet:

public class HttpServiceTracker extends ServiceTracker {
       public HttpServiceTracker(BundleContext context) {
           super(context, HttpService.class.getName(), null);
       }

public Object addingService(ServiceReference reference) {
final HttpService httpService = (HttpService) context
.getService(reference);
try {
//regist file upload servlet
HttpContext commonContext = new BundleEntryHttpContext(context
.getBundle(), fileFolder);
httpService.registerResources(fileContext, "/", commonContext);

Servlet adaptedJspServlet = new ContextPathServletAdaptor(
new FileUploadServlet(),
fileContext);
httpService.registerServlet(fileContext + "/fileupload.file",
adaptedJspServlet, null, commonContext);
           } catch (Exception e) {
               e.printStackTrace();
           }
           return httpService;
       }

public void removedService(ServiceReference reference, Object service) {
final HttpService httpService = (HttpService) service;
httpService.unregister(fileContext);
httpService.unregister(fileContext + "/fileupload.jsp");
super.removedService(reference, service);
}
}
start servlet:
  add these code to the bundle start up method.
 	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
       httpServiceTracker = new HttpServiceTracker(context);
       httpServiceTracker.open();
       System.out.println("IM resource servlet started...");
	}

 

这个实现是在RAP中使用Browser+servlet实现的文件上传功能;

其实在RAP的cvs上已经放出了org.eclipse.rwt.widgets.upload,专用于上传的组件,测试了一下,效果还不错,有进度条提示;不过在IE6下,有点难看了,在FF3下不能使用;

分享到:
评论

相关推荐

    ews.rar_EWS

    标题中的“ews.rar_EWS”很可能是指一个名为“EWS”的软件或库的源代码压缩包,其中“rar”是常见的压缩格式,用于打包多个文件。描述中提到的“ALSA driver for ICEnsemble ICE1712 (Envy24)”揭示了这个EWS项目与...

    ews.rar_DMX_EWS

    标题中的“ews.rar_DMX_EWS”表明这是一个与DMX(Digital Multiplexed Signal)和EWS(可能指的是Electronic Warfare System或类似系统)相关的压缩文件。这个文件集可能包含了用于编程或控制Terratec EWS88MT D、EW...

    board-rsi-ews.rar_rsi

    “board-rsi-ews.c”这个文件名暗示了这是一个C语言编写的源代码文件,它是Linux设备驱动程序的一部分,专门负责初始化RSI-EWS板卡。在Linux内核中,每个硬件设备都有对应的驱动程序,这些驱动程序通常包含了设备的...

    安卓发送Exchange邮件jar包:ews-android-api.jar

    安卓发送Exchange邮件,引用ews-android-api.jar和joda-time-2.8.jar两个包。 用法: ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); ExchangeCredentials credentials = new ...

    EWSJavaAPI_1.2.jar相关包。EWS Exchange连接邮箱源码

    EWS(Exchange Web Services)是微软Exchange Server提供的一种基于Web的接口,允许开发者通过编程方式访问和操作Exchange服务器上的邮箱、日历、联系人等数据。EWSJavaAPI_1.2.jar是针对Java开发者的EWS客户端库,...

    用EWSAPI在Java中发送Exchange邮件

    在IT行业中,Exchange Web Services (EWS) API 是一种用于与Microsoft Exchange Server进行通信的编程接口,它允许开发者通过各种编程语言(如Java)来执行邮件管理、日历操作、联系人同步等任务。本教程将详细介绍...

    印尼数字广播DVBT2 EWS技术标准.zip

    基于印尼数字广播电视EWS技术规范详解

    EWS jar 包下载

    Java implementation of the Exchange Web Services (EWS) API. This API gives developers programmatic access to Exchange Server 2007 SP1 and above. exchange web services api,支持2007sp1以上的版本

    evolution-ews-3.28.5-1.el7.x86_64.rpm

    evolution-ews-3.28.5-1.el7.x86_64.rpm

    ews-java-api-2.0

    EWS java API 里面包含 Java调用EWS 接口所需要的所有jar包如: commons-logging-1.2.jar joda-time-2.8.jar commons-lang3-3.4.jar httpclient-4.4.1.jar httpcore-4.4.1.jar

    evolution-ews-3.28.5-6.el7.i686.rpm

    evolution-ews-3.28.5-6.el7.i686.rpm

    EVOC 一体化工作站 EWS-844E.pdf.pdf

    EVOC 一体化工作站 EWS-844E.pdfpdf,EVOC 一体化工作站 EWS-844E.pdf

    使用EWS获取邮件

    EWS(Exchange Web Services)是Microsoft Exchange Server提供的一种API接口,允许开发者通过Web服务的方式与Exchange服务器进行交互,包括发送、接收、管理邮件以及访问日历、联系人等信息。在本文中,我们将深入...

    win8拇指输入

    标题“win8拇指输入”指的是在Windows 8操作系统中,为平板电脑用户设计的一种便捷的触摸屏输入方式,尤其适合使用拇指操作。Windows 8在设计时充分考虑了触控设备的需求,拇指输入就是其中一个重要特性,旨在提高在...

    ews临床反应解释(中英文).docx

    早期预警评分系统(Early Warning Score System, EWS)是一种用于评估患者临床状况的工具,它通过量化患者的一些基本生理指标来判断患者的健康状态,并据此提供相应的临床干预建议。EWS主要依据以下几个生理指标来...

    Python库 | suds-ews-0.3.7.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:suds-ews-0.3.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    evolution-ews-3.28.5-8.el7_9.i686.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    ewsManage:我使用Exchange Web Service(EWS)的练习

    我使用Exchange Web Service(EWS)的练习 作者:3gstudent 许可证:BSD 3-Clause 更多详细信息: 更新(2020.06.20): 添加新模式: CreateTestMail,创建测试邮件并将其保存到目标文件夹。 ...

    ews-client:用于访问日历、联系人等的 Exchange Web 服务客户端

    EWS(Exchange Web 服务)客户端 用于连接以交换和检索日历和联系信息的库。 该库使用 NTLM 与交换服务器进行身份验证。 安装 '''npm 安装 ews''' 用法 var ews = require ( 'ews' ) ; var mailbox = 'email@...

    DVB-EWS-Fact-sheet_DVB-EWS_

    dvb ews文档,可帮助大家了解ews方面的内容

Global site tag (gtag.js) - Google Analytics