I. BACKGROUND notes
In the project development process, the local development uses the Windows+tomcat, in the production, becomes the linux+weblogic. After the project is deployed, an error is applied to show that the Get app directory returns NULL.
On-line access to information, found in the WebLogic, the war package deployment, there is no way to apply the argument, so can only return null.
Two. Workaround
/** Get the root directory of the project * This method is required because Tomcat and WebLogic get the root directory inconsistencies*/ Privatestring Getwebrooturl (HttpServletRequest request) {string Filedirpath= Request.getsession (). Getservletcontext (). Getrealpath ("/"); if(Filedirpath = =NULL){ //If the return is empty, it means that the server is WebLogic, you need to use a different method Try{ returnRequest.getsession (). Getservletcontext (). GetResource ("/"). GetFile (); }Catch(malformedurlexception e) {LogUtil.MSG.info ("Error getting the root directory of the project!" ", E); Throw NewBizexception ("Error getting the root directory of the project! "); } }Else{ returnFiledirpath; } }
Tomcat under Output E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\bqsims_client\
WebLogic Output/home/weblogic/oracle/middleware/oracle_home/user_projects/domains/domain7101/servers/ adminserver7101/tmp/_wl_user/bqsims_client/i3sdnr/war/
WebLogic get the App directory path