extjs上传文件模块Word格式.docx

上传人:b****5 文档编号:20534371 上传时间:2023-01-23 格式:DOCX 页数:32 大小:26.18KB
下载 相关 举报
extjs上传文件模块Word格式.docx_第1页
第1页 / 共32页
extjs上传文件模块Word格式.docx_第2页
第2页 / 共32页
extjs上传文件模块Word格式.docx_第3页
第3页 / 共32页
extjs上传文件模块Word格式.docx_第4页
第4页 / 共32页
extjs上传文件模块Word格式.docx_第5页
第5页 / 共32页
点击查看更多>>
下载资源
资源描述

extjs上传文件模块Word格式.docx

《extjs上传文件模块Word格式.docx》由会员分享,可在线阅读,更多相关《extjs上传文件模块Word格式.docx(32页珍藏版)》请在冰豆网上搜索。

extjs上传文件模块Word格式.docx

x-plain'

 

42. 

43. 

labelWidth:

80, 

44. 

45. 

fileUpload:

true, 

46. 

47. 

defaultType:

textfield'

48. 

49. 

items:

[{ 

50. 

51. 

xtype:

52. 

53. 

fieldLabel:

文 

件'

54. 

55. 

name:

upload'

56. 

57. 

inputType:

file'

58. 

59. 

allowBlank:

false, 

60. 

61. 

blankText:

请上传文件'

62. 

63. 

anchor:

90%'

// 

anchor 

width 

by 

percentage 

64. 

65. 

}] 

66. 

67. 

});

68. 

69. 

70. 

71.var 

winUpload 

Ext.Window({ 

72. 

73. 

title:

资源上传'

74. 

75. 

width:

400, 

76. 

77. 

height:

200, 

78. 

79. 

minWidth:

300, 

80. 

81. 

minHeight:

100, 

82. 

83. 

layout:

fit'

84. 

85. 

plain:

86. 

87. 

bodyStyle:

padding:

5px;

88. 

89. 

buttonAlign:

center'

90. 

91. 

formUpload, 

92. 

93. 

buttons:

94. 

95. 

text:

上 

传'

96. 

97. 

handler:

function() 

98. 

99. 

if(formUpload.form.isValid()){ 

100. 

101. 

Ext.MessageBox.show({ 

102. 

103. 

Please 

wait'

104. 

105. 

msg:

Uploading...'

106. 

107. 

progressText:

108. 

109. 

110. 

111. 

progress:

112. 

113. 

closable:

114. 

115. 

animEl:

loding'

116. 

117. 

118. 

119. 

formUpload.getForm().submit({ 

120. 

121. 

url:

uploadAction.action?

types='

+types, 

122. 

123. 

success:

function(form, 

action){ 

124. 

125. 

var 

objxzdz 

Ext.get(uploadid).dom;

126. 

127. 

value 

action.result.msg;

128. 

129. 

objxzdz.value 

value;

130. 

131. 

Ext.Msg.alert('

成功'

'

上传成功.'

132. 

133. 

winUpload.hide();

134. 

135. 

}, 

136. 

137. 

failure:

action){ 

138. 

139. 

//... 

action生成的json{msg:

上传失败},页面就可以用action.result.msg得到非常之灵活 

140. 

141. 

Error'

 

action.result.msg);

142. 

143. 

144. 

145. 

}) 

146. 

147. 

148. 

149. 

150. 

151. 

},{ 

152. 

153. 

取 

消'

154. 

155. 

function(){winUpload.hide();

156. 

157. 

158. 

159. 

160. 

161.//*****************************************上传的公共js***************************************************************// 

162. 

163.现在已经封装完毕了,我们看看在页面上如何调用 

164.openUpload("

txt-xls-doc-docs-pds"

xzdzid"

165.就这一句话,嘿嘿,简单吧?

第一个参数为允许上传的类型,第二个参数为上传后地址要绑定到哪个控件(是该控件的id) 

166. 

167.action的代码还是贴下吧 

168.<

PRE 

class=java 

name="

code"

>

import 

java.io.File;

169. 

170.import 

java.io.FileInputStream;

171. 

172.import 

java.io.FileOutputStream;

173. 

174. 

175. 

176.import 

org.apache.struts2.ServletActionContext;

177. 

178. 

179. 

180.import 

mon.util.Common;

181. 

182.import 

mon.util.Constants;

183. 

184.import 

mon.util.FileOperate;

185. 

186.import 

mon.util.VeDate;

187. 

188. 

189. 

190./** 

191. 

192. 

上传的公共方法 

193. 

194. 

195. 

196. 

@author 

sam.zhang 

197. 

198. 

199. 

200. 

201. 

202.public 

class 

UploadAction 

extends 

ExtJsonActionSuport 

203. 

204. 

205. 

206. 

/** 

207. 

208. 

209. 

210. 

211. 

212. 

private 

static 

final 

long 

serialVersionUID 

1L;

213. 

214. 

215. 

//和前台的名字一样,这里约定是 

upload 

216. 

File 

upload;

217. 

218. 

219. 

220. 

String 

uploadContentType;

221. 

222. 

223. 

224. 

uploadFileName;

225. 

226. 

227. 

228. 

savePath;

229. 

230. 

231. 

232. 

存放允许上传的后缀名 

233. 

234. 

types;

235. 

236. 

237. 

238. 

public 

getSavePath() 

239. 

240. 

return 

241. 

242. 

243. 

244. 

245. 

246. 

void 

setSavePath(String 

savePath) 

247. 

248. 

this.savePath 

249. 

250. 

251. 

252. 

253. 

254. 

getUpload() 

255. 

256. 

257. 

258. 

259. 

260. 

261. 

262. 

setUpload(File 

upload) 

263. 

264. 

this.upload 

265. 

266. 

267. 

268. 

269. 

270. 

getUploadContentType() 

271. 

272. 

273. 

274. 

275. 

276. 

277. 

278. 

setUploadContentType(String 

uploadContentType) 

279. 

280. 

this.uploadContentType 

281. 

282. 

283. 

284. 

285. 

286. 

getUploadFileName() 

287. 

288. 

289. 

290. 

291. 

292. 

293. 

294. 

setUploadFileName(String 

uploadFileName) 

295. 

296. 

this.uploadFileName 

297. 

298. 

299. 

300. 

301. 

302. 

getTypes() 

303. 

304. 

305. 

306. 

307. 

308. 

309. 

310. 

setTypes(String 

types) 

311. 

312. 

this.types 

313. 

314. 

315. 

316. 

317. 

318. 

@SuppressWarnings("

deprecation"

) 

319. 

320. 

execute() 

throws 

Exception 

321. 

322. 

msg 

323. 

324. 

FileOperate 

fo 

FileOperate();

325. 

326. 

327. 

328. 

sid 

VeDate.getNo(4);

329. 

330. 

331. 

332. 

/updownFiles"

333. 

334. 

335. 

336. 

try 

337. 

338. 

339. 

340. 

...获取文件后缀名 

341. 

342. 

ext 

fo.getFileExt(getUploadFileName());

343. 

344. 

345. 

346. 

if 

("

.equals(this.types) 

347. 

348. 

|| 

Common.indexofString(this.types, 

-"

) 

== 

-1) 

349. 

350. 

上传失败"

351. 

352. 

this.setJsonString("

{success:

false,msg:

}"

353. 

354. 

SUCCESS;

355. 

356. 

357. 

358. 

359. 

360. 

...判断上传的文件是否合法 

361. 

362. 

boolean 

istrue 

FileOperate.trueExt(this.types.split("

), 

ext);

363. 

364. 

(!

istrue) 

365. 

366. 

您上传的文件格式不正确,正确格式为"

this.types;

367. 

368. 

369. 

370. 

371. 

372. 

373. 

374. 

375. 

376. 

...文件存放的位置 

377. 

378. 

sPath 

ServletActionContext.getRequest().getRealPath( 

379. 

380. 

this.getSavePath()) 

381. 

382. 

Constants.FILESPARA 

383. 

384. 

sid.substring(0, 

4) 

385. 

386. 

387. 

388. 

sid.substring(4, 

6) 

389. 

390. 

Constants.FILESPARA;

391. 

392. 

393. 

394. 

...保存在数据库的路径 

395. 

396. 

filePath 

/"

4) 

397. 

398. 

6) 

."

ext;

399. 

400. 

401. 

402. 

如果目录不存在则创建它 

403. 

404. 

405. 

406. 

fo.createFolder(sPath);

407. 

408. 

409. 

410. 

FileOutputStream 

fileOutputStream 

FileOutputStream(sPath 

411. 

412. 

413. 

414. 

415. 

416. 

FileInputStream 

fileInputStream 

FileInputStream(getUpload());

417. 

418. 

... 

419. 

420. 

byte[] 

buffer 

byte[1024];

421. 

422. 

int 

len 

0;

423. 

424. 

while 

((len 

fileInputStream.read(buffer)) 

0) 

425. 

426. 

fileOutputStream.write(buffer, 

0, 

len);

427. 

428. 

429. 

430. 

true,msg:

431. 

432. 

catch 

(Exception 

e) 

433. 

434. 

false}"

435. 

436. 

e.printStackTrace();

437. 

438. 

439. 

440. 

441. 

442. 

443. 

444. 

445. 

446.} 

447. 

448.<

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1