<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的關(guān)于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 阿南 閱讀(1787) 評論(0)  編輯  收藏 所屬分類: Eclipse-RAP

    主站蜘蛛池模板: www永久免费视频| 在线精品亚洲一区二区 | 亚洲人成电影院在线观看| 99精品视频在线观看免费| 久久亚洲av无码精品浪潮| 久香草视频在线观看免费| 亚洲一区二区精品视频| 两个人日本WWW免费版| 久久精品国产精品亚洲| 三根一起会坏掉的好痛免费三级全黄的视频在线观看 | 亚洲а∨天堂久久精品9966| 日韩精品福利片午夜免费观着| 亚洲最大天堂无码精品区| 最新69国产成人精品免费视频动漫| 亚洲人成人伊人成综合网无码| 免费看片免费播放| 免费一级做a爰片久久毛片潮| 国产亚洲av片在线观看18女人| 国产一区二区免费视频| 亚洲美女视频一区二区三区| 91精品国产免费入口| 2020亚洲男人天堂精品| 国产99视频免费精品是看6| 亚洲日韩在线观看免费视频| 久久精品国产精品亚洲蜜月| 日韩中文字幕精品免费一区| 亚洲av色香蕉一区二区三区蜜桃| www亚洲一级视频com| 免费一区二区三区| 亚洲妇女水蜜桃av网网站| 国产色婷婷精品免费视频| 岛国岛国免费V片在线观看| 久久亚洲精品无码AV红樱桃| 成人黄18免费视频| 国产成人自产拍免费视频| 亚洲精品一区二区三区四区乱码 | 亚洲sss综合天堂久久久| 一本色道久久88亚洲综合| 久久精品一区二区免费看| 亚洲中文字幕无码爆乳| 在线观看亚洲精品国产|