java上传文件时tomcat崩溃

在项目中,我用到的tomcat是5.5的,在linux上跑。最近发现在上传文件时,如果连续上传10个左右,就会出现tomcat崩溃的情况。JVM的内存我已经设置成为512M的了。现将代码分别贴出,请各位看一看:(是SSH架构的)

jsp:

<form action="tArenamessage.do" name="tArenamemessageForm" id="tArenamemessageForm" method="POST" onSubmit="return checkForm('tArenamemessageForm');" enctype="multipart/form-data" >
...
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="file" name="file3" />
....
/form>

===============================

struts.xml:

<form-bean name="TArenamemessageForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="name" type="java.lang.String" />
...
<form-property name="file1" type="org.apache.struts.upload.FormFile" />
<form-property name="file2" type="org.apache.struts.upload.FormFile" />
<form-property name="file3" type="org.apache.struts.upload.FormFile" />
</form>
<!-- 场馆管理模块 -->
<action path="/tArenamessage" scope="request" type="org.springframework.web.struts.DelegatingActionProxy" validate="false" name="TArenamemessageForm" >
<forward name="service" path="/../WEB-INF/jsp/admin/jsp/tArenamessage.jsp"> </forward>
</action>

====================================

aciton:

//保存
public boolean setBeanValueByDynaActionForm(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
this.myExecute(mapping, form, request, response);
DynaActionForm hzForm = (DynaActionForm) form;
...
FormFile localfile = null;
//外景照片
localfile = (FormFile)hzForm.get("file1");
if(localfile!=null) {this.upload(localfile, request, 6L);}

localfile = (FormFile)hzForm.get("file2");
if(localfile!=null) {this.upload(localfile, request, 6L);}

localfile = (FormFile)hzForm.get("file3");
if(localfile!=null) {this.upload(localfile, request, 6L);}

...
}
//上传文件
private void upload(FormFile localfile,HttpServletRequest request,long flag){
String finalFileName="";
if(localfile!=null) {
finalFileName = Upload.uploadAttachment( localfile , request);//上传文件
}
if(finalFileName != null && !finalFileName.equals("")){
uploadFile(localfile,request,finalFileName,flag);//保存到附件表
}
}

上传文件的类:
public class Upload {
public static String uploadAttachment( FormFile file , HttpServletRequest request){
if( SystemGlobal.uploadAccess[0].toString().indexOf(file.getContentType())>=0 && file.getFileSize() <= ( 2048 * (Integer.parseInt( SystemGlobal.uploadAccess[1].toString()) ))){ //是图片并且小于?k
String path = SystemGlobal.webDir(request) + SystemGlobal.uploadAccess[2] + System.getProperty("file.separator") + StringUtil.date2String() + System.getProperty("file.separator");
File dir = new File(path);
if(!dir.exists()){dir.mkdir();}
String filename = "";
if(!file.getFileName().equals("")){
try{
filename = StringUtil.time2String() + StringUtil.ramdom(4)+ "." + file.getFileName().substring(file.getFileName().length()-3) ;
InputStream stream = file.getInputStream();
FileOutputStream output = new FileOutputStream( path + filename );
int len = -1;
byte[] buf = new byte[102400];
while((len = stream.read(buf)) != -1){
output.write(buf,0,len);
}
output.close();
stream.close();
}catch(IOException e){Log.error( Upload.class , "upload write stream ha error:" + e);}
}
return filename;
}
return "";
}

==============================
tareamanage.hbm.xml 一对多,一个场馆可以有多个图片

<set name="TUploadfiles" inverse="false" cascade="save-update" fetch="subselect" lazy="false">
<cache usage="read-write"/>
<key>
<column name="OBJID" length="50" />
</key>
<one-to-many class="com.webaorta.comm.pojo.TUploadfile" />
</set>

====================================
大致上就是这些了,代码里是否存在不合理的地方而导致什么原因从而令到tomcat死掉了呢?tomcat里的logs也没有一点报错的信息可以看的。


后来我直接将其转换为open session in view模式,奇怪的是我在windows下可以运行(开发机),但在linux下就报session已经关闭这个错误的了。这又是为什么呢?(服务器是linux系统).

请各位看一看吧,如果搞不好这个可能会丢饭碗的。谢谢大家了。
展开阅读全文

上传文件tomcat崩溃

01-13

在项目中,我用到的tomcat是5.5的,在linux上跑。最近发现在上传文件时,如果连续上传10个左右,就会出现tomcat崩溃的情况。JVM的内存我已经设置成为512M的了。现将代码分别贴出,请各位帮忙看一看:(是SSH架构的)rnrnjsp:rnrn rn...rnrnrnrn....rn/form>rnrn===============================rnrnstruts.xml:rnrnrn rn ...rn rn rn rnrnrnrn rnrnrn====================================rnrnaciton:rnrn//保存rnpublic boolean setBeanValueByDynaActionForm(ActionMapping mapping, ActionForm form,rn HttpServletRequest request, HttpServletResponse response)rn this.myExecute(mapping, form, request, response); rn DynaActionForm hzForm = (DynaActionForm) form;rn ...rnFormFile localfile = null;rn//外景照片rnlocalfile = (FormFile)hzForm.get("file1"); rnif(localfile!=null) this.upload(localfile, request, 6L); rnrnlocalfile = (FormFile)hzForm.get("file2"); rnif(localfile!=null) this.upload(localfile, request, 6L);rnrnlocalfile = (FormFile)hzForm.get("file3"); rnif(localfile!=null) this.upload(localfile, request, 6L);rn rn...rnrn//上传文件rnprivate void upload(FormFile localfile,HttpServletRequest request,long flag)rn String finalFileName="";rn if(localfile!=null) rn finalFileName = Upload.uploadAttachment( localfile , request);//上传文件rn rn if(finalFileName != null && !finalFileName.equals(""))rn uploadFile(localfile,request,finalFileName,flag);//保存到附件表rn rnrnrn上传文件的类:rnpublic class Upload rn public static String uploadAttachment( FormFile file , HttpServletRequest request)rn if( SystemGlobal.uploadAccess[0].toString().indexOf(file.getContentType())>=0 && file.getFileSize() <= ( 2048 * (Integer.parseInt( SystemGlobal.uploadAccess[1].toString()) ))) //是图片并且小于?krn String path = SystemGlobal.webDir(request) + SystemGlobal.uploadAccess[2] + System.getProperty("file.separator") + StringUtil.date2String() + System.getProperty("file.separator"); rn File dir = new File(path);rn if(!dir.exists())dir.mkdir();rn String filename = "";rn if(!file.getFileName().equals(""))rn tryrn filename = StringUtil.time2String() + StringUtil.ramdom(4)+ "." + file.getFileName().substring(file.getFileName().length()-3) ; rn InputStream stream = file.getInputStream();rn FileOutputStream output = new FileOutputStream( path + filename );rn int len = -1;rn byte[] buf = new byte[102400];rn while((len = stream.read(buf)) != -1)rn output.write(buf,0,len);rn rn output.close();rn stream.close();rn catch(IOException e)Log.error( Upload.class , "upload write stream ha error:" + e);rn rn return filename;rn rn return "";rnrnrn==============================rntareamanage.hbm.xml 一对多,一个场馆可以有多个图片rnrnrnrn rn rn rn rnrn rn====================================rn大致上就是这些了,代码里是否存在不合理的地方而导致什么原因从而令到tomcat死掉了呢?tomcat里的logs也没有一点报错的信息可以看的。rnrnrn后来我直接将其转换为open session in view模式,奇怪的是我在windows下可以运行(开发机),但在linux下就报session已经关闭这个错误的了。这又是为什么呢?(服务器是linux系统).rnrn请各位高手帮忙看一看吧,如果搞不好这个可能会丢饭碗的。谢谢大家了。rnrnrnrnrnrn 论坛

没有更多推荐了,返回首页