首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > Apache >

struts2 文件下传有关问题 临时文件夹的 探讨

2012-12-29 
struts2文件上传问题临时文件夹的 探讨我用的是eclipsej2eeweb开发版!此问题纠结了半天了、、、据说是路径的

struts2 文件上传问题 临时文件夹的 探讨
我用的是eclipse  j2ee   web  开发版!
此问题纠结了半天了、、、据说是路径的问题我用\   /都试了,好像没处在这上面、、、不知其什么原因、、、各位帮帮看看



struts.xml

  <constant name="struts.multipart.saveDir" value="\tmp"></constant>
  <constant name="struts.mutilpart.maxSize" value="1024000"></constant>    
  <package name="upload"  extends = "struts-default">  
 <action name="upload" class = "org.leno.struts2.action.UploadAction">
 <interceptor-ref name="fileUpload">
 <param name="maxinmumSize">1024000</param>
 <param name="allowedTypes">text/plain</param>
 </interceptor-ref>
 <interceptor-ref name="defaultStack" ></interceptor-ref>
 
 <result name="success">/success.jsp</result>
 <result name= "input">/singleUpload.jsp</result>
 
 </action> 
 </package>



UploadAction.java  为:


        private File upload ;
private String uploadFileName;
private String uploadContentType;
                   、、、、、、
         String newroot = ServletActionContext.getServletContext().getRealPath("/upload");
System.out.println(newroot);

File dir = new File(newroot,getUploadFileName());
FileInputStream input = new FileInputStream(getUpload());
FileOutputStream output = new FileOutputStream(dir);

byte[] buf = new byte[100];
int len = 100;
while((len = input.read())>=0)
{
output.write(buf, 0, len);
}
input.close();
output.close();





问题是:

控制台信息为:

信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Program Files\Java\jdk1.6.0_16\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;D:/Program Files/Java/jre6/bin/client;D:/Program Files/Java/jre6/bin;D:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;D:\Program Files\Java\jdk1.6.0_16\bin;d:\webserver\lib\msbase.jar;d:\webserver\lib\mssqlserver.jar;d:\webserver\lib\msutil.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;D:\Program Files\MySQL\MySQL Server 5.1\bin;D:\Program Files\SVN\bin;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs
2010-10-26 16:00:01 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2010-10-26 16:00:01 org.apache.coyote.ajp.AjpProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8009
2010-10-26 16:00:01 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 493 ms
2010-10-26 16:00:01 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
2010-10-26 16:00:01 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.2


2010-10-26 16:00:01 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor UPload.xml from D:\eclipseWork\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost
2010-10-26 16:00:01 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(D:\eclipseWork\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\UPload\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
2010-10-26 16:00:01 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2010-10-26 16:00:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2010-10-26 16:00:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2010-10-26 16:00:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2010-10-26 16:00:02 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2010-10-26 16:00:02 org.apache.coyote.ajp.AjpProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2010-10-26 16:00:02 org.apache.catalina.startup.Catalina start
信息: Server startup in 1043 ms
页面报错:
    java.io.FileNotFoundException: \tmp\upload_25ffa761_12be618d792__8000_00000000.tmp (系统找不到指定的文件。)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(FileInputStream.java:106)
org.leno.struts2.action.UploadAction.execute(UploadAction.java:51)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)


com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:314)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)






[解决办法]
我也遇到同样的问题
求解

热点排行