SpringMvc 上传

1、js部分

a. 面板部分

 var uploadPanel = this.uploadPanel = new Ext.FormPanel({
            width: 600,
            height: 50,
            region: 'north',
            frame: true,
            layout: 'fit',
            fileUpload: true,
            closeAction:'hide',
            buttonAlign: 'center',
            layout: 'form',
            border:0,
            items:[
            {
                    layout: 'form',style:'margin-top:6px;margin-left:30px;',
                    items:[
                    {
                    xtype: 'fileuploadfield',
                    allowBlank:false,
                    blankText:'授权文件必须上传',
                    width: 370,
                    fieldLabel: '上传授权文件',
                    name:'uploadFile',
                    buttonText: '浏览'
                ]
                }
            ]
        })

b.必须是form提交。

                  uploadPanel.form.doAction('submit', {
url: '../role/saveRoleMenuFun.sdo',
method: 'post',
waitTitle:'请等待',
waitMsg: '正在提交...',
params: {roleId: id,menuIds:menuIds,jsonFunIds:Ext.encode(jsonFunIds),name:name},
timeout: 300000,//五分钟
success: function(form, action) {
if(action.result.success == true) {
Ext.MessageBox.alert('提示', '操作成功!');
}
else {
Ext.MessageBox.alert('提示', '操作失败:');
}
}
});

2、后台类

@RequestMapping("/saveRoleMenuFun.sdo")
public @ResponseBody String saveRoleMenuFun(HttpServletRequest request,HttpServletResponse response, 
  @RequestParam(value="menuIds", required=false) String menuIds,@RequestParam(value="jsonFunIds", required=false) String jsonFunIds,
  @RequestParam(value="name", required=false) String name,@RequestParam(value="roleId", required=false) String roleId)throws Exception {

purviewRoleService = (PurviewRoleService)SpringHelper.getBean("roleService");
JSONObject obj = new JSONObject();


MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile file = multipartRequest.getFile("uploadFile");
System.out.println(file.getSize());
purviewRoleService.saveRoleMenuFun(menuIds,jsonFunIds,file,roleId,name);

obj.put("success",true);
return obj.toString();
}


       /**
* 件文件保存到本地
* stream   文件流
* savaUrl  文件要写入的地址
* @param url
* @throws FileNotFoundException 
*/
public static  void SaveFile(InputStream stream,String savaUrl,String fileName) throws FileNotFoundException{
try {
OutputStream os = new FileOutputStream(new File(savaUrl+"/"+fileName));
int len = 0;
byte[] b = new byte[1024];
while ((len = stream.read(b)) > 0)
{
os.write(b, 0, len);
}
b = null;
stream.close();
os.close();
} catch (Exception e) {
e.printStackTrace();
}  

}


3、所需要包

commons-fileupload.jar

commons-io.jar

spring的包就不一一列举

4、xml配置文件

 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">            <property name="maxUploadSize" value="104857600"/>        

            <property name="maxInMemorySize" value="4096"/> 

</bean>


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值