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>
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值