如果web项目下有upload这个文件夹
在web.xml设置
<context-param>
<param-name>upload folder</param-name>
<param-value>upload</param-value>
</context-param>
在servlet中通过下面语句可以得到upload文件夹的路径
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext context=getServletConfig().getServletContext();//获取上下文
String uploadpath=context.getInitParameter("upload folder");//获取参数
String path=context.getRealPath(uploadpath);//得到文件夹upload的实际路径(例如E:\Soft\tomcat\tomcat6\webapps\atest\upload)atest为项目名称
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print("uploadpath : ");
out.print(path);
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}