My Web project name is Iamgemodel.
Working space on D-plate
Get URL Related first:
Need is httpservletrequest request;
Get IP:
// Server Address
Get Port:
Request.getserverport () // port number
Get Project name (out: Indicates result):
// Out:/imagemodel
Get request full URL path:
Request.getrequesturi (); // Out :/imagemodel/image/list.do
Get Parameters:
Request.getquerystring () // parameter
To get the physical path:
Get the project physical root path:
Request.getsession (). Getservletcontext (). Getrealpath ("/"); // out:d:\eclipseworkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\imagemodel\
Get the CLASSPATH (entity is a Class):
Entity.getclass (). getClassLoader (). GetResource ("/"). GetPath (); // Out :/d:/eclipseworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/imagemodel/web-inf /classes/
Get the file also ibid.
Get jar:
this. getclass (). getResourceAsStream (FileName);
Java gets the project path, URL path