When the J2EE development will not encounter a path, while the web is developed, there is a relative path and absolute path, and there is a difference between the web path and the real path. When such a problem, I can't remember it. Which methods should be called, so it is prepared in Blog.
Ready to work:
My website access path is: http://www.chho.com/test/index.do
The physical storage path of the website is: c: / chhoweb / root
Record start:
l Adding request.getContextPath () in the action, the result is the virtual path name behind the domain name, the above case is: [/ Test]
l Adverts servlet.getServletContext (). getRealPath ("Test.txt") in the action, the acquisition will be the real path of this website plus the file name in the parameter, that is, c: /chhoweb/root/test.txt, and Do not find this file is true, just simply obtain the physical path of this Do, and add a string of "Test.txt". Note: The test is done on Tomcat 5.0, and the Web container may cause the getRealPath to return different results.