JavaWeb the base (1) - file directory structure and create a project

1. JavaWeb application

  JavaWeb applications are divided into static and dynamic from the categories.

  Static application is the traditional static pages + HTML file asset structure, no special configuration. JavaWeb nor is it designed to do a static website.

  Dynamic application is a web-based database service (probably not very appropriate description), have more features and better interactivity. Because of these characteristics, it is necessary to stringent requirements for dynamic website is more complex and demanding.

  One of the most basic dynamic website consists of:

  | Project directory

    | src

    | web

      | WEB-INF

        | Web.xml: core profile

        | Lib: place the jar package folder

        | Classes: placing bytecode (compiled) file

      | Static resources

        | HTML/CSS/JS/Image/Video……

      | Jsp

 

2. web.xml

  A complete and standardized JavaWeb project, there must be a web.xml file, this file is used to configure the Filter, Listener, Servlet and so on.

  When Tomcat starts, first read the web.xml Tomcat installation directory conf folder as the global configuration, and then read the updated project web.xml global configuration.

  web.xml commonly used tags:

<!-- schema头 -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<web-app version="4.0" 
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
</web-app>

<! - text description -> 
< disciption > This IS A Simple XML. </ Disciption >

<! - configuration application context information -> 
< context-param > 
    < param-name > ContextParameter </ para-name > 
    < param-value > Test </ param-value > 
    < Description > It IS A Test Parameter. < / Description > 
</ context-param >

<!-- 过滤器 filter -->
<filter>
    <filter-name>setCharacterEncoding</filter-name>
    <filter-class>com.myTest.setCharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>setCharacterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 监听器 listener -->
<listener> 
    <listerner-class>com.listener.SessionListener</listener-class> 
</listener>

<!-- Servlet -->
<servlet>
    <servlet-name>snoop</servlet-name>
    <servlet-class>SnoopServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>snoop</servlet-name>
    <url-pattern>/snoop</url-pattern>

<! - Session Timeout configuration (min) -> 
< the session-config > 
    < the session-timeout > 120 </ the session-timeout > 
</ the session-config >

<!-- 欢迎页 -->
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
</welcome-file-list>

<!-- 错误页(错误码\异常类型) -->
<error-page>
    <error-code>404</error-code>
    <location>/NotFound.jsp</location>
</error-page>
<error-page>
    <exception-type>java.lang.NullException</exception-type>
    <location>/Error.jsp</location>
</error-page>

 

3. WEB-INF

  WEB-INF directory is a directory of web application security, as the security directory that can be accessed directly on the server side and can not be accessed by the client, the client wants to access must be configured by the server.

  Directory to store the configuration of the web application file web.xml; there are storage jar package lib web directory needs; there are stored compiled .class files in the directory classes. Would not want to be placed in the client user to access files directly to this folder, you can effectively protect file security.

 

4. Create a simple project (IDEA)

  (1) Select the Java Enterprise, select / add JDK version, EE version, Tomcat path and version, check the Web Application, create web.xml.

  

  (2) Select whether to use the template to create.

  

  (3) setting the project name, select items to place directory, select the schema version of web.xml, to configure a Tomcat (as with the first step).

  

  (4) At this time we have created a simple JavaWeb project.

  

Guess you like

Origin www.cnblogs.com/NyanKoSenSei/p/11641856.html