- apollo_r
- 等级: 初级会员
- 文章: 20
- 积分: 54
- 来自: ...
|
在站内搜索了一下,没有找到类似的问题
1。页面只有上传的的form,包括:file框,text框,上传按钮。有时候能上传,有时不能上传成功,不成功提示http 500 dispatch[/photoManage]...错误,但是同样一个ActionForward为什么有时可以,有时不可以。
2。struts自带的token会不会影响上传呢?
3。是不是代码有问题,各位同胞们帮我看下,代码如下:
java 代码
-
-
- public ActionForward sendOnePhoto(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
-
- PhotoManageForm photoForm = (PhotoManageForm) form;
- HttpSession session = request.getSession();
- session.removeAttribute("photoname");
- String ep_no = (String) session.getAttribute("ep_no");
-
- String photo_name = photoForm.getPhoto_name();
- if (photo_name == null && "".equals(photo_name)) {
- request.setAttribute("photoname", "isEmpty");
- return new ActionForward("/searchPhoto.do?flag=manage");
- }
- FormFile file = photoForm.getFile();
- String filename = file.getFileName();
-
- session.setAttribute("photoname", photo_name);
- int filesize = file.getFileSize();
- String firstname = "";
-
- if (isTokenValid(request, true)) {
- try {
- PhotoNameSearch namesearch = new PhotoNameSearch();
- firstname = namesearch.String2Alpha(photo_name).substring(0, 1);
- System.out.println("首拼音是:" + firstname);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- Date date = new Date();
- String datename = date.toString();
- datename = datename.replaceAll(" ", "");
- datename = datename.replaceAll(":", "");
- String sql = "";
-
- if (filename != null && !filename.equals("")) {
- int index = filename.lastIndexOf(".");
- String sn = filename.substring(index, filename.length());
-
- if (!sn.equalsIgnoreCase(".gif")
- && !sn.equalsIgnoreCase(".jpg")
- && !sn.equalsIgnoreCase(".png")) {
- return new ActionForward("/searchPhoto.do?selepno=" + ep_no+ "&error=format");
- }
- if (filesize > 1024 * 1024 * 5) {
- return new ActionForward("/searchPhoto.do?selepno=" + ep_no+ "&error=size");
- }
-
- Calendar c = Calendar.getInstance();
- SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
- String datetime = f.format(c.getTime());
- System.out.println("====" + datetime);
-
- String savepath = request.getRealPath("/") + "/upload/photo/"+ datename + sn;
- sql = "insert into photo(ep_no,photo_name,photo_route,upload_date,firstname) values('"
- + StrTrans.transGbk(ep_no)
- + "','"
- + StrTrans.transGbk(photo_name)
- + "','"
- + StrTrans.transGbk(datename + sn)
- + "','"
- + datetime
- + "','" + firstname + "')";
-
- CommonDataBean commonDataBean = null;
- InputStream in = null;
- FileOutputStream out = null;
-
- try {
- in = file.getInputStream();
- out = new FileOutputStream(savepath);
- commonDataBean = new CommonDataBean();
- byte[] b = new byte[30000000];
- int i = 0;
- while ((i = in.read(b)) != -1) {
- out.write(b, 0, i);
- }
-
- out.close();
- in.close();
- commonDataBean.executeUpdate(sql);
-
- photoHandle ph = new photoHandle();
- ph.updatetime(ep_no);
- } catch (Exception e) {
- System.out.println(e.getMessage());
- e.printStackTrace();
- System.out.println("something wrong!");
- } finally {
- commonDataBean.closeConn();
- }
- }
- resetToken(request);
- } else {
- saveToken(request);
- }
- return new ActionForward("/searchPhoto.do?flag=manage");
- }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- esprit
- 等级:
- 性别:
- 文章: 14
- 积分: 149
- 来自: 杭州
|
其他的没仔细看下去
if (photo_name == null && "".equals(photo_name)) {
request.setAttribute("photoname", "isEmpty");
return new ActionForward("/searchPhoto.do?flag=manage");
}
这段有问题,不是&&,而是||,要仔细啊,呵呵
|
返回顶楼 |
|
|
- apollo_r
- 等级: 初级会员
- 文章: 20
- 积分: 54
- 来自: ...
|
esprit 写道 其他的没仔细看下去
if (photo_name == null && "".equals(photo_name)) {
request.setAttribute("photoname", "isEmpty");
return new ActionForward("/searchPhoto.do?flag=manage");
}
这段有问题,不是&&,而是||,要仔细啊,呵呵 哦,谢谢,
但这个地方应该不是上传的问题的症结啊
|
返回顶楼 |
|
|