---
title: "etxjs+ssh的CRUD(3)-----combobox&上传文件"
author: ":倾诉"
date: "2011-06-16T00:35:39Z"
tags: []
categories: ["Web前端"]
slug: "etxjs-ssh-crud-3-combobox"
draft: false
lastmod: "2011-06-16T00:35:39Z"
id: 1092763
url: "https://xiaopier.iteye.com/blog/1092763"
---

最后剩下图书管理的,同样有查询,新增,更新,删除,代码跟用户管理的差不多,

不同的是以下几个地方,即下拉框,文件上传

```
items:[{
	xtype:"form",
	layout:"form",
	fileUpload :true,//要上传文件,一定要这么一句
        items:[{
	     xtype:"combo",//选择框
	     fieldLabel:"类别",
	     displayField:"catalogname",
	     valueField:"catalogid",//实际传往后台的值
     	     hiddenName:"ctlgname",//后台request这个ctlgname就能得到实际传的valueField值
	     emptyText:"--请选择--",
	     store:catalogStore,
	     mode:'local',
	     width:90
       },{
	     xtype:"textfield",
	     fieldLabel:"上传图片",
	     name:"picture",
	     inputType:"file"//表示文件上传
       }
}]
```

 

 store定义如下,跟普通grid需要的store差不多

```
var catalogStore = new Ext.data.JsonStore({
	reader :new Ext.data.JsonReader(),
	root:'result',
	proxy:new Ext.data.HttpProxy({
		url:"admin!queryAllCatalog"
	}),
	fields:["catalogid","catalogname"]
});
```

 上传文件到了后台这么处理:

 关键代码:

```
public String addBook() throws IOException {
        String realPath = ServletActionContext.getRequest().getRealPath("/picture");//生成文件的路径,到tomcat发布该项目的目录下
//System.out.println(realPath);
	String imageName = new Long(new Date().getTime()).toString();//用时间命名文件
	File target = new File(realPath+ "/" + imageName + ".bmp");//目标文件
	File image = new File(getPicture().toString());//源文件,getPicture()获得后台传来的pictrue路径
        try {
		FileUtils.copyFile(image,target);//拷贝文件
	} catch (IOException e) {
		System.out.println( "copy出错");
	}
}
```

 打印结果为:

F:\\Program Files\\tomcat-6.0.30\\apache-tomcat-6.0.30\\webapps\\bookstore\\picture

 

 

至此,一个简单的结合extjs的ssh作业完成