Ext.form.field.파일 예

2359 단어
Ext.onReady(function(){
			Ext.QuickTips.init();
			var uploadForm = Ext.create('Ext.form.Panel', {
				title: 'Ext.form.field.File ',
				bodyStyle: 'padding:5 5 5 5',// 
				width: 300,
				frame: true,
				renderTo: 'form',
				fieldDefaults: { // 
					labelSeparator: ':', // 
					labelWidth: 50, // 
					width: 150, // 
					allowBlank: false,// 
					labelAlign: 'left',// 
					msgTarget: 'side'
				},
				items: [{
					xtype: 'filefield',
					name: 'photo',
					fieldLabel: ' ',
					anchor: '100%',
					buttonText: ' ...'
				}],
				buttons: [{
					text: ' ',
					handler: function(){
						var form = uploadForm.getForm();
						if(form.isValid){
							form.submit({
								url: 'uploadServer.jsp',
								waitMsg: ' ...',
								success: function(fp, o){
									Ext.Msg.alert(' ', '  "' + o.result.file + '" 。');
								}
							});
						}
					}
				}]
			});
		});
<%@ page language="java" import="java.util.*, org.apache.commons.fileupload.*, org.apache.commons.fileupload.FileItem" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
	<%
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		DiskFileUpload upload = new DiskFileUpload();
		upload.setHeaderEncoding("utf-8");
		java.util.List items;
		try {
			items = upload.parseRequest(request);
			java.util.ListIterator listIterator = items.listIterator();
			String fileName = "";
			while(listIterator.hasNext()){
				FileItem item = (FileItem)listIterator.next();
				if(!item.isFormField()){
					fileName = item.getName();
					fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);// 
					System.out.println(fileName);
				}
			}
			String msg = "{success: true, file: '" + fileName + "'}";
			
			response.getWriter().write(msg);
		} catch (FileUploadException e) {
			e.printStackTrace();
		}
	 %>

좋은 웹페이지 즐겨찾기