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

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

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

    大夢想家

    5年開發(fā)工程師,2年實(shí)施經(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...");
    	}

     

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

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



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

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


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 蜜臀91精品国产免费观看| 亚洲精品视频久久久| 亚洲第一成年免费网站| 国产av无码专区亚洲国产精品| 最近2019中文免费字幕在线观看| 亚洲电影在线播放| 亚洲欭美日韩颜射在线二| 亚洲精品国产精品| 久久久久亚洲?V成人无码| 亚洲网站在线免费观看| 看全免费的一级毛片| 亚洲宅男永久在线| 亚洲高清偷拍一区二区三区| 日韩在线永久免费播放| 亚洲av无码无在线观看红杏| 久久久久久久91精品免费观看| a级毛片免费高清视频| 亚洲av无码国产综合专区| 亚洲性猛交XXXX| 国产免费69成人精品视频| 最近中文字幕大全中文字幕免费 | 免费又黄又硬又爽大片| 美女免费视频一区二区三区| 亚洲国产精品lv| 又大又粗又爽a级毛片免费看| 麻豆视频免费播放| 中文在线观看永久免费| 99亚洲男女激情在线观看| 亚洲精品在线电影| 亚洲精品无码成人AAA片| 国产无遮挡裸体免费视频 | 亚洲免费观看在线视频| 精品一区二区三区高清免费观看| 亚洲中文字幕久久久一区| 丁香亚洲综合五月天婷婷| 最近最新的免费中文字幕| 无码精品一区二区三区免费视频 | 老司机永久免费网站在线观看| 99热这里只有精品免费播放| 香蕉免费一级视频在线观看| 欧美日韩亚洲精品|