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-INF/classes/目录下的类、和 WEB-INF/lib/目录下JAR包中的类,对该web应用下的其它类可见,但对其它的web应用不可见。
  • 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
│          
└─websocket
        chat.xhtml
        drawboard.xhtml
        echo.xhtml
        index.xhtml
        snake.xhtml
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值