当前位置: 首页 > news >正文

Java web应用的目录结构

详情可以参考:
https://tomcat.apache.org/tomcat-10.1-doc/appdev/deployment.html
https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0.html#directory-structure

Java web应用根目录下包含如下内容:

  • *.html, *.jsp等:html、jsp文件及其它必须对客户端浏览器可见的文件(如JavaScript、样式文件、图片文件)。对于大型的应用,可以将这些文件划分成子目录的结构存放;对于小型应用,可以不再区分子目录。
  • /WEB-INF/web.xml :应用部署描述符文件。这个文件描述了组成应用的servlet及其它的成分、需要容器执行的初始化参数、安全约束等。
  • /WEB-INF/classes/:这个目录下存放了应用需要的任何Java类文件(及关联的资源),包含没有放在 JAR文件中的servlet类、非servlet类。如果Java类是以Java包组织的,那么包的层次结构必须/WEB-INF/classes/下面体现出来,例如,一个类的名字是com.thb.DemoServlet,必须存放为/WEB-INF/classes/com/thb/DemoServlet.class。
  • /WEB-INF/lib/ :这个目录存放着JAR文件,例如第三方类库或者JDBC驱动(driver)。这些JAR文件中包含应用需要的servlet、bean、静态资源、JSP文件、及其它工具类(utility classes)。

对WEB-INF目录的进一步说明:

  • web应用类加载器首先从WEB-INF/classes目录加载类,然后再从 WEB-INF/lib目录下的JAR文件中加载。
  • WEB-INF目录包含了跟应用相关的、但不在应用根目录下的所有东西。
  • WEB-INF下的绝大部分不属于应用的公共文档树的一部分,除了打包到JAR文件中META-INF/resources目录下的静态资源和JSP文件以外,WEB-INF目录下的其它文件不允许容器给客户端提供访问。
  • WEB-INF目录对servlet代码可见,方式是通过ServletContext的getResource 和getResourceAsStream方法调用。

举例:tomcat安装包中自带的examples这个web应用的目录结构如下:

D:\APACHE-TOMCAT-10.1.13\WEBAPPS\EXAMPLES
│  index.html
│  
├─jsp
│  │  index.html
│  │  
│  ├─async
│  │      async1.jsp
│  │      async1.jsp.html
│  │      async3.jsp
│  │      async3.jsp.html
│  │      index.jsp
│  │      index.jsp.html
│  │      
│  ├─cal
│  │      cal1.jsp
│  │      cal1.jsp.html
│  │      cal2.jsp
│  │      cal2.jsp.html
│  │      calendar.html
│  │      Entries.java.html
│  │      Entry.java.html
│  │      JspCalendar.java.html
│  │      login.html
│  │      TableBean.java.html
│  │      
│  ├─checkbox
│  │      check.html
│  │      checkresult.jsp
│  │      checkresult.jsp.html
│  │      CheckTest.html
│  │      cresult.html
│  │      
│  ├─colors
│  │      clr.html
│  │      ColorGameBean.html
│  │      colors.html
│  │      colrs.jsp
│  │      colrs.jsp.html
│  │      
│  ├─dates
│  │      date.html
│  │      date.jsp
│  │      date.jsp.html
│  │      
│  ├─error
│  │      er.html
│  │      err.jsp
│  │      err.jsp.html
│  │      error.html
│  │      errorpge.jsp
│  │      errorpge.jsp.html
│  │      
│  ├─forward
│  │      forward.jsp
│  │      forward.jsp.html
│  │      fwd.html
│  │      one.jsp
│  │      one.jsp.html
│  │      two.html
│  │      
│  ├─images
│  │      code.gif
│  │      execute.gif
│  │      return.gif
│  │      
│  ├─include
│  │      foo.html
│  │      foo.jsp
│  │      foo.jsp.html
│  │      inc.html
│  │      include.jsp
│  │      include.jsp.html
│  │      
│  ├─jsp2
│  │  ├─el
│  │  │      basic-arithmetic.html
│  │  │      basic-arithmetic.jsp
│  │  │      basic-arithmetic.jsp.html
│  │  │      basic-comparisons.html
│  │  │      basic-comparisons.jsp
│  │  │      basic-comparisons.jsp.html
│  │  │      composite.html
│  │  │      composite.jsp
│  │  │      composite.jsp.html
│  │  │      functions.html
│  │  │      Functions.java.html
│  │  │      functions.jsp
│  │  │      functions.jsp.html
│  │  │      implicit-objects.html
│  │  │      implicit-objects.jsp
│  │  │      implicit-objects.jsp.html
│  │  │      ValuesBean.java.html
│  │  │      ValuesTag.java.html
│  │  │      
│  │  ├─jspattribute
│  │  │      FooBean.java.html
│  │  │      HelloWorldSimpleTag.java.html
│  │  │      jspattribute.html
│  │  │      jspattribute.jsp
│  │  │      jspattribute.jsp.html
│  │  │      shuffle.html
│  │  │      shuffle.jsp
│  │  │      shuffle.jsp.html
│  │  │      ShuffleSimpleTag.java.html
│  │  │      TileSimpleTag.java.html
│  │  │      
│  │  ├─jspx
│  │  │      basic.html
│  │  │      basic.jspx
│  │  │      basic.jspx.html
│  │  │      svgexample.html
│  │  │      textRotate.html
│  │  │      textRotate.jpg
│  │  │      textRotate.jspx
│  │  │      textRotate.jspx.html
│  │  │      
│  │  ├─misc
│  │  │      coda.jspf
│  │  │      coda.jspf.html
│  │  │      config.html
│  │  │      config.jsp
│  │  │      config.jsp.html
│  │  │      dynamicattrs.html
│  │  │      dynamicattrs.jsp
│  │  │      dynamicattrs.jsp.html
│  │  │      EchoAttributesTag.java.html
│  │  │      prelude.jspf
│  │  │      prelude.jspf.html
│  │  │      
│  │  ├─simpletag
│  │  │      book.html
│  │  │      book.jsp
│  │  │      book.jsp.html
│  │  │      BookBean.java.html
│  │  │      FindBookSimpleTag.java.html
│  │  │      Functions.java.html
│  │  │      hello.html
│  │  │      hello.jsp
│  │  │      hello.jsp.html
│  │  │      HelloWorldSimpleTag.java.html
│  │  │      repeat.html
│  │  │      repeat.jsp
│  │  │      repeat.jsp.html
│  │  │      RepeatSimpleTag.java.html
│  │  │      
│  │  └─tagfiles
│  │          displayProducts.tag.html
│  │          hello.html
│  │          hello.jsp
│  │          hello.jsp.html
│  │          helloWorld.tag.html
│  │          panel.html
│  │          panel.jsp
│  │          panel.jsp.html
│  │          panel.tag.html
│  │          products.html
│  │          products.jsp
│  │          products.jsp.html
│  │          
│  ├─jsptoserv
│  │      hello.jsp
│  │      hello.jsp.html
│  │      jsptoservlet.jsp
│  │      jsptoservlet.jsp.html
│  │      jts.html
│  │      ServletToJsp.java.html
│  │      
│  ├─num
│  │      numguess.html
│  │      numguess.jsp
│  │      numguess.jsp.html
│  │      
│  ├─security
│  │  └─protected
│  │          error.jsp
│  │          error.jsp.html
│  │          index.jsp
│  │          index.jsp.html
│  │          login.jsp
│  │          login.jsp.html
│  │          
│  ├─sessions
│  │      carts.html
│  │      carts.jsp
│  │      carts.jsp.html
│  │      crt.html
│  │      DummyCart.html
│  │      
│  ├─simpletag
│  │      foo.html
│  │      foo.jsp
│  │      foo.jsp.html
│  │      
│  ├─snp
│  │      snoop.html
│  │      snoop.jsp
│  │      snoop.jsp.html
│  │      
│  ├─tagplugin
│  │      choose.html
│  │      choose.jsp
│  │      choose.jsp.html
│  │      foreach.html
│  │      foreach.jsp
│  │      foreach.jsp.html
│  │      howto.html
│  │      if.html
│  │      if.jsp
│  │      if.jsp.html
│  │      notes.html
│  │      
│  └─xml
│          xml.html
│          xml.jsp
│          xml.jsp.html
│          
├─META-INF
│      context.xml
│      
├─servlets
│  │  cookies.html
│  │  helloworld.html
│  │  index.html
│  │  reqheaders.html
│  │  reqinfo.html
│  │  reqparams.html
│  │  sessions.html
│  │  
│  ├─images
│  │      code.gif
│  │      execute.gif
│  │      return.gif
│  │      
│  └─nonblocking
│          bytecounter.html
│          
├─WEB-INF
│  │  web.xml
│  │  
│  ├─classes
│  │  │  CookieExample.class
│  │  │  CookieExample.java
│  │  │  HelloWorldExample.class
│  │  │  HelloWorldExample.java
│  │  │  LocalStrings.properties
│  │  │  LocalStrings_cs.properties
│  │  │  LocalStrings_de.properties
│  │  │  LocalStrings_es.properties
│  │  │  LocalStrings_fr.properties
│  │  │  LocalStrings_ja.properties
│  │  │  LocalStrings_ko.properties
│  │  │  LocalStrings_pt.properties
│  │  │  LocalStrings_pt_BR.properties
│  │  │  LocalStrings_ru.properties
│  │  │  LocalStrings_zh_CN.properties
│  │  │  RequestHeaderExample.class
│  │  │  RequestHeaderExample.java
│  │  │  RequestInfoExample.class
│  │  │  RequestInfoExample.java
│  │  │  RequestParamExample.class
│  │  │  RequestParamExample.java
│  │  │  ServletToJsp.class
│  │  │  ServletToJsp.java
│  │  │  SessionExample.class
│  │  │  SessionExample.java
│  │  │  
│  │  ├─async
│  │  │      Async0$1.class
│  │  │      Async0.class
│  │  │      Async0.java
│  │  │      Async1$1.class
│  │  │      Async1.class
│  │  │      Async1.java
│  │  │      Async2$1.class
│  │  │      Async2.class
│  │  │      Async2.java
│  │  │      Async3.class
│  │  │      Async3.java
│  │  │      AsyncStockContextListener.class
│  │  │      AsyncStockContextListener.java
│  │  │      AsyncStockServlet.class
│  │  │      AsyncStockServlet.java
│  │  │      Stockticker$Stock.class
│  │  │      Stockticker$TickListener.class
│  │  │      Stockticker.class
│  │  │      Stockticker.java
│  │  │      
│  │  ├─cal
│  │  │      Entries.class
│  │  │      Entries.java
│  │  │      Entry.class
│  │  │      Entry.java
│  │  │      JspCalendar.class
│  │  │      JspCalendar.java
│  │  │      TableBean.class
│  │  │      TableBean.java
│  │  │      
│  │  ├─checkbox
│  │  │      CheckTest.class
│  │  │      CheckTest.java
│  │  │      
│  │  ├─colors
│  │  │      ColorGameBean.class
│  │  │      ColorGameBean.java
│  │  │      
│  │  ├─compressionFilters
│  │  │      CompressionFilter.class
│  │  │      CompressionFilter.java
│  │  │      CompressionFilterTestServlet.class
│  │  │      CompressionFilterTestServlet.java
│  │  │      CompressionResponseStream.class
│  │  │      CompressionResponseStream.java
│  │  │      CompressionServletResponseWrapper.class
│  │  │      CompressionServletResponseWrapper.java
│  │  │      
│  │  ├─dates
│  │  │      JspCalendar.class
│  │  │      JspCalendar.java
│  │  │      
│  │  ├─error
│  │  │      Smart.class
│  │  │      Smart.java
│  │  │      
│  │  ├─examples
│  │  │      ExampleTagBase.class
│  │  │      ExampleTagBase.java
│  │  │      FooTag.class
│  │  │      FooTag.java
│  │  │      FooTagExtraInfo.class
│  │  │      FooTagExtraInfo.java
│  │  │      LogTag.class
│  │  │      LogTag.java
│  │  │      ValuesTag.class
│  │  │      ValuesTag.java
│  │  │      
│  │  ├─filters
│  │  │      ExampleFilter.class
│  │  │      ExampleFilter.java
│  │  │      
│  │  ├─http2
│  │  │      SimpleImagePush.class
│  │  │      SimpleImagePush.java
│  │  │      
│  │  ├─jsp2
│  │  │  └─examples
│  │  │      │  BookBean.class
│  │  │      │  BookBean.java
│  │  │      │  FooBean.class
│  │  │      │  FooBean.java
│  │  │      │  ValuesBean.class
│  │  │      │  ValuesBean.java
│  │  │      │  
│  │  │      ├─el
│  │  │      │      Functions.class
│  │  │      │      Functions.java
│  │  │      │      
│  │  │      └─simpletag
│  │  │              EchoAttributesTag.class
│  │  │              EchoAttributesTag.java
│  │  │              FindBookSimpleTag.class
│  │  │              FindBookSimpleTag.java
│  │  │              HelloWorldSimpleTag.class
│  │  │              HelloWorldSimpleTag.java
│  │  │              RepeatSimpleTag.class
│  │  │              RepeatSimpleTag.java
│  │  │              ShuffleSimpleTag.class
│  │  │              ShuffleSimpleTag.java
│  │  │              TileSimpleTag.class
│  │  │              TileSimpleTag.java
│  │  │              
│  │  ├─listeners
│  │  │      ContextListener.class
│  │  │      ContextListener.java
│  │  │      SessionListener.class
│  │  │      SessionListener.java
│  │  │      
│  │  ├─nonblocking
│  │  │      ByteCounter$CounterListener.class
│  │  │      ByteCounter.class
│  │  │      ByteCounter.java
│  │  │      NumberWriter$NumberWriterListener.class
│  │  │      NumberWriter.class
│  │  │      NumberWriter.java
│  │  │      
│  │  ├─num
│  │  │      NumberGuessBean.class
│  │  │      NumberGuessBean.java
│  │  │      
│  │  ├─sessions
│  │  │      DummyCart.class
│  │  │      DummyCart.java
│  │  │      
│  │  ├─trailers
│  │  │      ResponseTrailers$TrailerFieldSupplier.class
│  │  │      ResponseTrailers.class
│  │  │      ResponseTrailers.java
│  │  │      
│  │  ├─util
│  │  │      CookieFilter.class
│  │  │      CookieFilter.java
│  │  │      HTMLFilter.class
│  │  │      HTMLFilter.java
│  │  │      
│  │  ├─validators
│  │  │      DebugValidator.class
│  │  │      DebugValidator.java
│  │  │      
│  │  └─websocket
│  │      │  ExamplesConfig.class
│  │      │  ExamplesConfig.java
│  │      │  
│  │      ├─chat
│  │      │      ChatAnnotation.class
│  │      │      ChatAnnotation.java
│  │      │      
│  │      ├─drawboard
│  │      │  │  Client$1.class
│  │      │  │  Client.class
│  │      │  │  Client.java
│  │      │  │  DrawboardContextListener.class
│  │      │  │  DrawboardContextListener.java
│  │      │  │  DrawboardEndpoint$1.class
│  │      │  │  DrawboardEndpoint$2.class
│  │      │  │  DrawboardEndpoint$3$1.class
│  │      │  │  DrawboardEndpoint$3.class
│  │      │  │  DrawboardEndpoint.class
│  │      │  │  DrawboardEndpoint.java
│  │      │  │  DrawMessage$ParseException.class
│  │      │  │  DrawMessage.class
│  │      │  │  DrawMessage.java
│  │      │  │  Room$1$1.class
│  │      │  │  Room$1.class
│  │      │  │  Room$2.class
│  │      │  │  Room$MessageType.class
│  │      │  │  Room$Player.class
│  │      │  │  Room.class
│  │      │  │  Room.java
│  │      │  │  
│  │      │  └─wsmessages
│  │      │          AbstractWebsocketMessage.class
│  │      │          AbstractWebsocketMessage.java
│  │      │          BinaryWebsocketMessage.class
│  │      │          BinaryWebsocketMessage.java
│  │      │          CloseWebsocketMessage.class
│  │      │          CloseWebsocketMessage.java
│  │      │          StringWebsocketMessage.class
│  │      │          StringWebsocketMessage.java
│  │      │          
│  │      ├─echo
│  │      │      EchoAnnotation.class
│  │      │      EchoAnnotation.java
│  │      │      EchoAsyncAnnotation$CompletedFuture.class
│  │      │      EchoAsyncAnnotation.class
│  │      │      EchoAsyncAnnotation.java
│  │      │      EchoEndpoint$EchoMessageHandlerBinary.class
│  │      │      EchoEndpoint$EchoMessageHandlerText.class
│  │      │      EchoEndpoint.class
│  │      │      EchoEndpoint.java
│  │      │      EchoStreamAnnotation.class
│  │      │      EchoStreamAnnotation.java
│  │      │      servers.json
│  │      │      
│  │      └─snake
│  │              Direction.class
│  │              Direction.java
│  │              Location$1.class
│  │              Location.class
│  │              Location.java
│  │              Snake.class
│  │              Snake.java
│  │              SnakeAnnotation.class
│  │              SnakeAnnotation.java
│  │              SnakeTimer$1.class
│  │              SnakeTimer.class
│  │              SnakeTimer.java
│  │              
│  ├─jsp
│  │      403.jsp
│  │      403.jsp.html
│  │      debug-taglib.tld
│  │      example-taglib.tld
│  │      jsp2-example-taglib.tld
│  │      
│  ├─lib
│  │      taglibs-standard-impl-1.2.5-migrated-0.0.1.jar
│  │      taglibs-standard-spec-1.2.5-migrated-0.0.1.jar
│  │      
│  └─tags
│          displayProducts.tag
│          helloWorld.tag
│          panel.tag
│          
└─websocketchat.xhtmldrawboard.xhtmlecho.xhtmlindex.xhtmlsnake.xhtml
http://www.lryc.cn/news/219429.html

相关文章:

  • 【Mac环境搭建】JDK安装、多JDK安装与切换
  • C++: 类和对象(中)
  • 图片批量归类:告别混乱,实现高效文件管理
  • 187. 重复的DNA序列 --力扣 --JAVA
  • Mysql高级——Mysql8一主一从,多主多从搭建
  • 【Qt5】QNetworkAccessManager
  • zookeeper节点类型
  • 【C++】一篇文章搞懂auto关键字及其相关用法!
  • 微信小程序overflow-x超出部分样式不渲染
  • Oracle常用运维SQL-SQL执行性能及锁表等查询分析
  • 安装MySQL时出现 由于找不到 MSVCR120.dll,无法继续执行代码。重新安装程序可能会解决此问题。
  • 【基础IO⑧】:文件描述符fd(进程与文件的联系)
  • 搭建WAMP网站教程(windows+apache+mysql+php)
  • 瓦斯抽采VR应急救援模拟仿真系统筑牢企业安全生产防线
  • nodelist 与 HTMLCollection 的区别
  • 系列十二、过滤器 vs 拦截器
  • dockerfile运行apk命令卡住的问题解决——更换镜像
  • Android - 编译 openssl 踩坑之路
  • verdi技巧分享--合并多个fsdb文件、统计信号边沿
  • czmq的4版本中CURVE怎么实现的两个程序之间使用的一个证书?
  • Spring Boot整合Swagger
  • SpringBoot-WebSocket浏览器-服务器双向通信
  • Docker网络模式_Docker常用命令_以及Docker如何给运行的镜像内容连接互联网_Docker网络模式原理---Docker工作笔记004
  • 爬虫项目-爬取股吧(东方财富)评论
  • 【Midjourney入门教程2】Midjourney的基础操作和设置
  • 后端使用DES加密,前端解密方法
  • chrome 扩展 popup 弹窗的使用
  • Spring Security入门教程,springboot整合Spring Security
  • 如何在 Unbuntu 下安装配置 Apache Zookeeper
  • AI视觉领域流媒体知识入门介绍(二):深入理解GOP