日期:2014-05-16  浏览次数:20441 次

Extjs 4.0 上传图片 + struts2

有了上传图片控件后 在action 中必须写上以下代码?

  1. response.setCharacterEncoding("utf-8");??
  2. ????????response.setContentType("text/html"); ?

// action代码

public String load4() {
		
		System.out.println("获取到了abcd:"+abcd);
		success = "true";
		upload.upload("abcdefg.jpg", abcd,
				"C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\needMovie\\"
						+"testImage" + "\\");
		Watch watch = new Watch();
		watch.setNum(1);
		watch.setOnLine("asdfasdf");
		videoManager.save();
		JSONObject jo = JSONObject.fromObject(watch);
		String jsonStr = jo.toString();
		System.out.println(jsonStr);
		
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        
		try {
			// 返回成功标识
			//response.getWriter().println("{success:true}");
			response.getWriter().println("{success:true,watch:"+jsonStr+"}");
			response.getWriter().flush();
			//response.getWriter().notify();
		} catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			try {
				response.getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}



		System.out.println("插入成功");
		return null;

	}
?
// 前台代码

artist: {
            xtype: 'panel', // since we are not using the default 'panel' xtype,
							// we must specify it
            title:'登录',  
            width:350,  
            id:'artist-panel',  
            items:[{  
                xtype:'form',  
                id:'artist-form',  
                defaultType:'textfield',  
                bodyStyle : 'padding:5px', 
                method:'POST',  
                defaults:{  
                    anchor:'95%',  
                },  
                items:[{  
                    id:'loginName',  
                    name:'loginName',  
                    fieldLabel:'用户名',   
                },{  
                    id:'password',  
                    name:'password',  
                    fieldLabel:'密码',  
                },{
                	 xtype: 'filefield',
                     id: 'abcd',
                     emptyText: 'Select an image',
                     fieldLabel: 'Photo',
                     name: 'abcd',
                     buttonText: 'asdfasdf',
                     
                }] 
            }],
            
            buttons: [{
                text: 'Save',
                handler: function(){
           	
            	var loginForm = Ext.getCmp('artist-form').form; 
            	loginForm.doAction('submit', {  
                    url:'save!load4.action',  
                    method:'POST',                        
                    waitMsg:'正在登陆...',  
                    timeout:10000,// 10秒超时,
                    // params:log