java web 路径 .html,java web 路径(java web 路径).doc

java web 路径(java web 路径)

java web 路径(java web 路径)

The path used in Java, divided into two types: absolute and relative paths. After all, the essence of Java can only use the absolute path to find resources. Methods all the relative path to find resources, but some convenience methods. But API is at the bottom and help us build the absolute path, in order to find the resources!

The application of Web in the development of the physical path, often need to get the current WebRoot in the server.

If it is Servlet, Action, Controller, or Filter, Listener, interceptor and other related classes, we only need to get the ServletContext, and then ServletContext.getRealPath ("/") to obtain the physical address of the application on the server.

If in the class not to ServletContext, there are two ways to do:

1. using Java class loading mechanism called XXX.class.getClassLoader (.GetResource) (""); to get to the ClassPath, and then processed to obtain the WebRoot directory, the only way is to take effect in the class WebRoot/WEB-INF/classes, if the class is packaged into a jar file, the method of failure. Then you should use the following ways.

2. spring framework, in WEB-INF/web.xml, create a webAppRootKey param, specify a value (default is webapp.root) as the key, and then through the Listener, or Filter, or Servlet String webAppRootKey (getServletContext) executive =.GetRealPath ("/"); and the corresponding webAppRootKey webapp.root as Key Value wrote. The System attribute in Properties system. Later in the program by System.getProperty ("webapp.root") to obtain the physical path of WebRoot.

According to the second kinds of ideas, we can expand out. But for the application in the deployment in a server, if it is not what you need. Please look down.

Here are some ways to get the classpath and some of the current class absolute path. Some of the ways you can use the absolute path in which to get the resources you need:

1. ("DebitNoteAction.class.getResource")

The FileTest.class URI is the current class

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值