struts下传的跳转有关问题

struts上传的跳转问题

在站内搜索了一下,没有找到类似的问题
1。页面只有上传的的form,包括:file框,text框,上传按钮。有时候能上传,有时不能上传成功,不成功提示http 500 dispatch[/photoManage]...错误,但是同样一个ActionForward为什么有时可以,有时不可以。
2。struts自带的token会不会影响上传呢?
3。是不是代码有问题,各位同胞们帮我看下,代码如下:

 

java 代码
  1. // 上传一张照片   
  2. //class photoManage   
  3. public ActionForward sendOnePhoto(ActionMapping mapping, ActionForm form,   
  4.     HttpServletRequest request, HttpServletResponse response) {   
  5.   
  6.     PhotoManageForm photoForm = (PhotoManageForm) form;   
  7.     HttpSession session = request.getSession();   
  8.     session.removeAttribute("photoname");   
  9.     String ep_no = (String) session.getAttribute("ep_no");   
  10.   
  11.     String photo_name = photoForm.getPhoto_name();// 图片别名   
  12.     if (photo_name == null && "".equals(photo_name)) {   
  13.                          request.setAttribute("photoname""isEmpty");   
  14.         return new ActionForward("/searchPhoto.do?flag=manage");   
  15.     }   
  16.     FormFile file = photoForm.getFile();   
  17.     String filename = file.getFileName();// 图片的源名+扩展名   
  18.   
  19.     session.setAttribute("photoname", photo_name);   
  20.     int filesize = file.getFileSize();   
  21.     String firstname = "";   
  22.   
  23.     if (isTokenValid(request, true)) {   
  24.         try {   
  25.             PhotoNameSearch namesearch = new PhotoNameSearch();   
  26.             firstname = namesearch.String2Alpha(photo_name).substring(01);// 取图片别名首拼音   
  27.             System.out.println("首拼音是:" + firstname);   
  28.         } catch (Exception ex) {   
  29.             ex.printStackTrace();   
  30.         }   
  31.         // 用作文件名的处理   
  32.         Date date = new Date();   
  33.         String datename = date.toString();   
  34.         datename = datename.replaceAll(" """);   
  35.         datename = datename.replaceAll(":""");   
  36.         String sql = "";// SQL语句   
  37.   
  38.         if (filename != null && !filename.equals("")) {   
  39.             int index = filename.lastIndexOf(".");// 得到.的位置   
  40.             String sn = filename.substring(index, filename.length()); // 求得扩展名   
  41.   
  42.             if (!sn.equalsIgnoreCase(".gif")   
  43.                 && !sn.equalsIgnoreCase(".jpg")   
  44.                 && !sn.equalsIgnoreCase(".png")) {   
  45.                 return new ActionForward("/searchPhoto.do?selepno=" + ep_no+ "&error=format");   
  46.             }   
  47.             if (filesize > 1024 * 1024 * 5) {   
  48.                 return new ActionForward("/searchPhoto.do?selepno=" + ep_no+ "&error=size");   
  49.             }   
  50.   
  51.             Calendar c = Calendar.getInstance();   
  52.             SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");   
  53.             String datetime = f.format(c.getTime());   
  54.             System.out.println("====" + datetime);   
  55.   
  56.             String savepath = request.getRealPath("/") + "/upload/photo/"+ datename + sn;// 上传文件写到相应路径目录下   
  57.             sql = "insert into photo(ep_no,photo_name,photo_route,upload_date,firstname) values('"  
  58.             + StrTrans.transGbk(ep_no)   
  59.             + "','"  
  60.             + StrTrans.transGbk(photo_name)   
  61.             + "','"  
  62.             + StrTrans.transGbk(datename + sn)   
  63.             + "','"  
  64.             + datetime   
  65.             + "','" + firstname + "')";   
  66.   
  67.             CommonDataBean commonDataBean = null;   
  68.             InputStream in = null;   
  69.             FileOutputStream out = null;   
  70.   
  71.             try {   
  72.                 in = file.getInputStream();   
  73.                 out = new FileOutputStream(savepath);   
  74.                 commonDataBean = new CommonDataBean();   
  75.                 byte[] b = new byte[30000000];   
  76.                 int i = 0;   
  77.                 while ((i = in.read(b)) != -1) {   
  78.                     out.write(b, 0, i);   
  79.                 }   
  80.   
  81.                 out.close();   
  82.                 in.close();   
  83.                     commonDataBean.executeUpdate(sql);   
  84.                 // 更新上传时间   
  85.                 photoHandle ph = new photoHandle();   
  86.                 ph.updatetime(ep_no);   
  87.             } catch (Exception e) {   
  88.                 System.out.println(e.getMessage());   
  89.                 e.printStackTrace();   
  90.                 System.out.println("something wrong!");   
  91.             } finally {   
  92.                                  commonDataBean.closeConn();   
  93.             }   
  94.         }   
  95.         resetToken(request);   
  96.     } else {   
  97.         saveToken(request);   
  98.     }   
  99.     return new ActionForward("/searchPhoto.do?flag=manage");   
  100. }  
1 楼 esprit 2007-01-15  
其他的没仔细看下去
if (photo_name == null && "".equals(photo_name)) {    
                         request.setAttribute("photoname", "isEmpty");    
        return new ActionForward("/searchPhoto.do?flag=manage");    
    }    

这段有问题,不是&&,而是||,要仔细啊,呵呵
2 楼 apollo_r 2007-01-15  
esprit 写道
其他的没仔细看下去
if (photo_name == null && "".equals(photo_name)) {    
                         request.setAttribute("photoname", "isEmpty");    
        return new ActionForward("/searchPhoto.do?flag=manage");    
    }    

这段有问题,不是&&,而是||,要仔细啊,呵呵
哦,谢谢,
但这个地方应该不是上传的问题的症结啊