`
junjun16818
  • 浏览: 104170 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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:loginForm.getValues(),
                    success:function(form, action){  
            			alert('登陆成功'+action.result.watch.onLine)
                        var isSuc = action.result.success;
                        if(isSuc) {  
                            // 提示用户登陆成功
                            Ext.Msg.alert('消息', '登陆成功..');  
                        }                                         
                    },  
                    failure:function(form, action){  
                        alert('登陆失败');  
                    }  
                });  
            	
					
            	
                }
            }]
        }
    };

 //XML 代码

<package name="ajax" extends="json-default">
        <action name="save" class="com.junjun.television.web.VideoAction">
            <result  type="json" name="success"/>
            
        </action>
    </package>
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics