日期:2014-05-17  浏览次数:21078 次

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
信息