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

java web 路径 .html,java web 路径(java web 路径).doc相关推荐

  1. java获取项目的部署目录结构_JAVA WEB项目目录结构以及web应用部署的根目录,编译路径和项目根目录的区别...

    本文链接:https://blog.csdn.net/l00149133/article/details/78984083 web应用部署的根目录,编译路径和项目的根目录有什么区别? 直接上例子: 你 ...

  2. Java嵌入式数据库H2学习总结(三)——在Web应用中嵌入H2数据库

    H2作为一个嵌入型的数据库,它最大的好处就是可以嵌入到我们的Web应用中,和我们的Web应用绑定在一起,成为我们Web应用的一部分.下面来演示一下如何将H2数据库嵌入到我们的Web应用中. 一.搭建测 ...

  3. java怎么监听多个组件,java web(五):java web三大组件之另外两个和八大监听器

    java的三大组件指Servlet.Filter.Listener.八大监听器指八个接口.前面介绍了Servlet,现在介绍一下Filter拦截器以及拦截地址的设置, Listener监听那些事件. ...

  4. java servlet 开发_Java之基于Servlet的Web开发简介

    由于学习的过程中,接触到了这部分内容,所以特别的在这进行整理,分享给大家. 1.定义 Servlet是Java Servlet的简称,称为小服务程序或服务连接器: 2.原理 从原理上讲,Servlet ...

  5. java动态工程_eclipse 创建maven 项目 动态web工程完整示例

    转自:https://www.cnblogs.com/noteless/p/5213075.html 此处只是使用maven 注意,以下所有需要建立在你的eclipse等已经集成配置好了maven了, ...

  6. java表单单击路径_Form表单中的action路径问题,form表单action路径《jsp---Servlet路劲问题》这个和上一个《jsp---Servlet》文章有关...

    Form表单中的action路径问题,form表单action路径 今天刚接触web,在用jsp和servlet做一个简单的登陆的时候在Form表单action属性和method属性的一些问题: 我遇 ...

  7. java当前类路径_java获取当前类的绝对路径

    另,Class类还有一个getResourceAsStream方法,记得以前有个项目要读取在同一个包内的一个xml,就用的这个. 1.如何获得当前文件路径 常用: (1).Test.class.get ...

  8. java web工程中如何添加图片_java web中如何添加图片

    java web中如何添加图片 对于java可视化界面插入背景图片只需要background-image:url(图片路径)就行,而对于web项目中,并非如此 效果如下: 我们就需要在jsp页面中写J ...

  9. Java如何获取IP属地 ip2region failed to create searcher with x:java.io.FileNotFoundException:( 系统找不到指定的路径)

    目录 引言 获取ip地址 使用ServerHttpRequest获取ip完整地址: 获取ip地址的源代码 接口调用源代码 使用HttpServletRequest获取ip完整地址 获取ip地址的源代码 ...

  10. Java WEB开发实战 之 第二部分:Web应用基础知识【私塾在线原创】

    基础知识概述 Internet 中文名也称"因特网"或"国际互联网",是一个由各种独立运行和管理的计算机网络组成的全球范围的计算机网络,网络间可以畅通无阻地交换 ...

最新文章

  1. 项目10天投产,测试仅剩2天,如何处理?
  2. iOS开发之指定UIView的某几个角为圆角
  3. WebStorm使用ES6
  4. 使用WebSocket绕过广告屏蔽插件
  5. HTML5自定义数据属性data-*
  6. 浅谈对程序员的认识_浅谈程序员的英语学习
  7. 花书+吴恩达深度学习(九)优化方法之二阶近似方法(牛顿法, CG, BFGS, L-BFGS)
  8. zabbix系列(八)zabbix添加对web页面url的状态监控
  9. 关于系统响应函数OnSysCommand
  10. 君康人寿2019年排名_君康人寿易主后 内部提出五年上市计划
  11. oracle读取blob字段的方法,如何读取Oracle的BLOB字段里的文件?
  12. 论文中的CNN网络绘制软件
  13. 摄影基础知识——曝光和测光
  14. 博通无线网卡驱动安装linux,Ubuntu下Broadcom 802.11g无线网卡驱动安装方法
  15. 原生安卓开发!最详细的解释小白也能听懂,全网独家首发!
  16. AD7606 SPI模式 网上问题汇总
  17. html另存为对话框,前端实现弹出“另存为”对话框的三种方式
  18. JAVA大华摄像头抓拍与API接口集成
  19. python高效控制模拟器_Appium+python自动化(五)- 模拟器(超详解)
  20. PARWAN处理器架构特点

热门文章

  1. CSS兼容性问题的解决方式(更新中···)
  2. 解决<c:if>无else的问题
  3. Android开发中遇到的问题(四)——Android中WARNING: Application does not specify an API level requirement!的解决方法
  4. 如何使用jQuery将事件附加到动态HTML元素? [重复]
  5. 撤消git pull,如何将repos带到旧状态
  6. Map 参数按Key重新排序,重组成String
  7. python 局域网通信_python实现局域网内实时通信代码
  8. pycharm配置python第三方库_解决pycharm每次新建项目都要重新安装一些第三方库的问题...
  9. Mysql的去重distinct
  10. 实验2-2-7 整数四则运算 (10 分)