我的JAVA代码如下:/**
* 编辑用户头像信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward editTopImg(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception {
log.debug("请求到这里来了....");
try{
//创建文件上传组件
SmartUpload smart = new SmartUpload();
ServletConfig config = this.getServlet().getServletConfig();
//初始化上传组件
smart.initialize(config, request, response);
//准备上传
smart.upload();
//获取文件后缀
String ext = smart.getFiles().getFile(0).getFileExt();
log.debug("获取到的上传文件的后缀是:"+ext);
String name = UUID.randomUUID().toString();
//保持稳健
smart.getFiles().getFile(0).saveAs("/images/userTop/"+name+"."+ext);
//更新用户信息
int userId = this.getIntParameter(request,"id");
GgUser user = userService.findUniqueBy("id",userId);
user.setTopImg(name+"."+ext);
//更新用户信息
userService.save(user);
//将用户信息存放到request作用域中
this.saveAttributeToRequest(request,"user",user);
}catch(Exception ex){
ex.printStackTrace();
}
return mapping.findForward(USER_INFO_EDIT);
}debug打印的:
DEBUG - 请求到这里来了....后面就不动了,也不向后执行了。。请问是哪里出问题了呢?
* 编辑用户头像信息
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward editTopImg(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception {
log.debug("请求到这里来了....");
try{
//创建文件上传组件
SmartUpload smart = new SmartUpload();
ServletConfig config = this.getServlet().getServletConfig();
//初始化上传组件
smart.initialize(config, request, response);
//准备上传
smart.upload();
//获取文件后缀
String ext = smart.getFiles().getFile(0).getFileExt();
log.debug("获取到的上传文件的后缀是:"+ext);
String name = UUID.randomUUID().toString();
//保持稳健
smart.getFiles().getFile(0).saveAs("/images/userTop/"+name+"."+ext);
//更新用户信息
int userId = this.getIntParameter(request,"id");
GgUser user = userService.findUniqueBy("id",userId);
user.setTopImg(name+"."+ext);
//更新用户信息
userService.save(user);
//将用户信息存放到request作用域中
this.saveAttributeToRequest(request,"user",user);
}catch(Exception ex){
ex.printStackTrace();
}
return mapping.findForward(USER_INFO_EDIT);
}debug打印的:
DEBUG - 请求到这里来了....后面就不动了,也不向后执行了。。请问是哪里出问题了呢?
smart.upload();这句就卡住了 不向后走了!
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 上传初始化
su.initialize(pageContext);
// 设定上传限制
// 1.限制每个上传文件的最大长度。
// su.setMaxFileSize(10000);
// 2.限制总上传数据的长度。
// su.setTotalMaxFileSize(20000);
// 3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
// su.setAllowedFilesList("doc,txt");
// 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat,
//jsp,htm,html扩展名的文件和没有扩展名的文件。
// su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// 上传文件
su.upload();
// 将上传文件全部保存到指定目录
int count = su.save("D:/temp");
out.println(count+"个文件上传成功! <br>"); // 利用Request对象获取参数之值
out.println("TEST="+su.getRequest().getParameter("TEST")
+" <BR> <BR>"); // 逐一提取上传文件信息,同时可保存文件。
for (int i=0;i <su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i); // 若文件不存在则继续
if (file.isMissing()) continue; // 显示当前文件信息
out.println(" <TABLE BORDER=1>");
out.println(" <TR> <TD>表单项名(FieldName) </TD> <TD>"
+ file.getFieldName() + " </TD> </TR>");
out.println(" <TR> <TD>文件长度(Size) </TD> <TD>" +
file.getSize() + " </TD> </TR>");
out.println(" <TR> <TD>文件名(FileName) </TD> <TD>"
+ file.getFileName() + " </TD> </TR>");
out.println(" <TR> <TD>文件扩展名(FileExt) </TD> <TD>"
+ file.getFileExt() + " </TD> </TR>");
out.println(" <TR> <TD>文件全名(FilePathName) </TD> <TD>"
+ file.getFilePathName() + " </TD> </TR>");
out.println(" </TABLE> <BR>"); // 将文件另存
// file.saveAs("/upload/" + myFile.getFileName());
// 另存到以WEB应用程序的根目录为文件根目录的目录下
// file.saveAs("/upload/" + myFile.getFileName(),
//su.SAVE_VIRTUAL);
// 另存到操作系统的根目录为文件根目录的目录下
// file.saveAs("c:\\temp\\" + myFile.getFileName(),
//su.SAVE_PHYSICAL); }这是放在JSP里的
su.initialize(pageContext); 实例化之后,su没值
我出现这样的情况