|
楼主 |
发表于 2013-5-5 17:35:12
|
显示全部楼层
GIN 发表于 2013-5-5 17:28
把控制器的代码一起贴出来看看
我现在改了下table方式布局连保存按钮都不执行方法了。
1. <t:dgToolBar title="景点录入" icon="icon-add" url="jdController.do?add" funname="add"></t:dgToolBar>
file:///F:/1.JPG
2.进入录入界面
<t:formvalid layout="table" dialog="false" formid="formobj" callback="submitproject" action="jdController.do?saveImgs">
<table cellpadding="0" cellspacing="1" class="formtable">
<tbody>
<tr>
<td align="right">
<label class="Validform_label">景区图片:</label>
</td>
<td class="value">
<t:upload queueID="img" multi="true" name="fiels" buttonText="选择文件" dialog="false"
uploader="jdController.do?saveImgs" extend="pic" id="file_upload"
formData="shortName,level,detail,sid,pid"></t:upload>
</td>
</tr>
<tr>
<td colspan="2" id="img" class="value"></td>
</tr>
</tbody>
</table>
</t:formvalid>
file:///F:/2.JPG
3.controller
@RequestMapping(params = "saveImgs", method = RequestMethod.POST)
@ResponseBody
public AjaxJson saveImgs(HttpServletRequest request) throws Exception {
AjaxJson j = new AjaxJson();
String fileName = null;
UploadFile uploadFile = new UploadFile(request);
String ctxPath = request.getSession().getServletContext().getRealPath("");
File file = new File(ctxPath);
if (!file.exists()) {
file.mkdir();// 创建文件根目录
}
MultipartHttpServletRequest multipartRequest = uploadFile.getMultipartRequest();
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile mf = entity.getValue();// 获取上传文件对象
fileName = mf.getOriginalFilename();// 获取文件名
String savePath = file.getPath() + "/" + fileName;// 上传后的文件绝对路径
System.out.println("上传后路径:"+savePath);
File savefile = new File(savePath);
try {
FileCopyUtils.copy(mf.getBytes(), savefile);
} catch (IOException e) {
e.printStackTrace();
}
}
message = "上传成功";
j.setMsg(message);
return j;
} |
|