<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    大夢想家

    5年開發(fā)工程師,2年實施經(jīng)理,X年售前顧問,......
    數(shù)據(jù)加載中……
    一段來自ews.eclipse.technology.rap的關于Upload a file的代碼

    I impleted my File upload/download system with rap internal Browser + servlet.
    upload dialog&#65306;

    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...");
    	}

     

    這個實現(xiàn)是在RAP中使用Browser+servlet實現(xiàn)的文件上傳功能;

    其實在RAP的cvs上已經(jīng)放出了org.eclipse.rwt.widgets.upload,專用于上傳的組件,測試了一下,效果還不錯,有進度條提示;不過在IE6下,有點難看了,在FF3下不能使用;



    客戶虐我千百遍,我待客戶如初戀!

    posted on 2008-01-11 13:17 阿南 閱讀(1780) 評論(0)  編輯  收藏 所屬分類: Eclipse-RAP

    主站蜘蛛池模板: 免费a级毛片视频| 亚洲卡一卡2卡三卡4卡无卡三| 亚洲午夜电影一区二区三区| 无码专区AAAAAA免费视频| 日韩精品成人无码专区免费| 亚洲国产一区视频| 四虎必出精品亚洲高清| 亚洲人成色4444在线观看| 日本不卡高清中文字幕免费| 亚洲黄色激情视频| 青柠影视在线观看免费| 亚洲无码视频在线| 国产精品亚洲一区二区麻豆| 最近2019中文字幕mv免费看| 亚洲国产午夜精品理论片在线播放| 国产无遮挡吃胸膜奶免费看视频 | 亚洲成a人片在线观看日本| 国产在线观看xxxx免费| 久久亚洲熟女cc98cm| 蜜桃AV无码免费看永久| 亚洲一区二区三区国产精品| 国产精品综合专区中文字幕免费播放 | 久久亚洲精品成人AV| 亚色九九九全国免费视频| 亚洲中文字幕无码av永久| 久草免费福利资源站| 亚洲国产精品综合久久2007| 99re6在线视频精品免费| 亚洲A∨午夜成人片精品网站| 久久久久se色偷偷亚洲精品av| 中文字幕免费在线观看动作大片| 亚洲va无码手机在线电影| 亚洲一区二区免费视频| 色天使色婷婷在线影院亚洲| 国产亚洲成人在线播放va| 国产VA免费精品高清在线| 日木av无码专区亚洲av毛片| 国产精品久免费的黄网站| 无码人妻一区二区三区免费看| 亚洲最大无码中文字幕| 国产黄色一级毛片亚洲黄片大全|