原因:在开发过程中,进行项目redeploy时,IDE会检测到webapps目录下已经有这个文件夹,有的话会删除这个文件夹,然后再将最新编译的代码部署过去,所以里面的东西都没了......
1.清空/tomcat/webapps/目录
2.修改/tomcat/conf/web.xml文件:
<servlet>
<servlet-name>default<servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet<servlet-class>
<init-param>
<param-name>debug<param-name>
<param-value>0<param-value>
</init-param>
<init-param>
<param-name>listing<sparam-name>
<param-value>true<param-value>
</init-param>
<load-on-startup>1<load-on-startup>
</servlet>
3.修改/tomcat/conf/server.xml文件:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/ser" docBase="D:/project/myProject/ddWebRoot">Context>
</Host>
String tomcatPath =context.getRealPath("/");//获取到tomcat位于系统的绝对磁盘路径,精确到项目下.此为:D:apache-tomcat-8.0.36webappsmychat
tomcatPath = tomcatPath.substring(0,tomcatPath.length()-1);//此为:D:apache-tomcat-8.0.36webappsmychat
tomcatPath = tomcatPath.substring(0,tomcatPath.lastIndexOf(""));//此为:D:apache-tomcat-8.0.36webapps
String relpath = tomcatPath+"upload"+file.getMeta().getFileLocalName(); // 此为: D:apache-tomcat-8.0.36webappsupload omat.png
System.out.println("tomcatPath:"+tomcatPath);