我想将一张图片发布到我的服务器(tomcat 7.0.40)上。
该项目是基于apache-struts2-2.2.1和spring 3.6以及apache-commons-fileupload构建的。首先,我做了一些html代码。
<input type="file" name="xxx" id="ccc" /> 好了,下一个。我做了一个扩展ActionSupport的动作。
public XxxAction extends ActionSupport{
private java.io.File xxx;
public String execute() throws Exception{
......
}
//getter and setter below
}下一步,spring config注入的操作如下:
<bean id="xxxAction" class="xxx.xxx.XxxAction" />也许你已经发现我丢失了scope="prototype",但请忽略它,因为问题不在那里。
接下来,由struts2.xml配置如下:
<package name="xxx" namespace="/xxx" extends="json-default">
<action name="upload" class="xxxAction">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/bmp,image/gif,image/jpg</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>
<param name="root">toFrontJson</param>
</result>
</action>
</package>好的,现在向server.We提交一个pic文件,假设该文件可以通过操作接收。但是当图片大到可以暂时通过的时候,我就关闭了浏览器。它将得到SocketTimeOut异常。我在tomcat配置文件夹中找到了server.xml,连接超时设置为20000。最重要的是当我得到这个例外的时候。此操作的其他请求无法访问。它将得到:
cannot find aciton or result ......
我认为SocketTimeOut异常一定会导致一些事情的发生。它让操作实例消失。所以我在spring.xml中添加了scope="prototype"。它起作用了。虽然当我中断fileupload操作时,我得到了一些其他异常,但其他请求是正常的。
但我希望在添加scope="prototype"之前知道发生了什么,为什么其他请求找不到操作,以及为什么我得到SocketTimeOut异常。
在apache-commons-fileupload中?还是Struts2?
发布于 2015-06-28 18:25:21
Spring使用的默认作用域是singleton。所以你的代码会因为文件上的同步IO操作而失败。
当您将其更改为prototype时,每个操作都有自己的action bean实例,因此它们使用自己的字段,并且不会相互粘连。
https://stackoverflow.com/questions/31096348
复制相似问题