The first Java Web program

1, the new Java Web Project

  • file-> new -> project ...
    Here Insert Picture Description
    This version 4.0 default
    Here Insert Picture Description
  • finish creating the project a success.
    alt+1 Expand or hide the project, look at the directory structure

Here Insert Picture Description

  • Lib directory and create a class
    that is often less than the actual project, this knowledge for knowledge.
    Create two folders lib and classes under WEB-INF
    Here Insert Picture Description
  • Under modify index.jsp
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/1/20 0020
  Time: 10:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>My First Page</title>
  </head>
  <body>
  <center><H1>Hello World</H1></center>
  </body>
</html>

  • Click on the upper right corner to run
    Here Insert Picture Description
    the upper right corner there is a cat, next click Run, he directly opened my browser 360 - because it is the default browser
    Here Insert Picture Description
    is amazing, JDK is not configured, tomct no configuration, it supports java environment experience , and servlet container.
    There are instructions at the beginning of the project to create a default configuration.

2, project configuration

file–>project structure…

  • Modify out path, a path that is stored after the class compiled
    Here Insert Picture Description
  • Configuring JDK
    Project SDK can be re-used in the selection of JDK version
    Here Insert Picture Description
  • Add dependent jar directory
    now maven core era, even if added to the jar jar also upload a public warehouse company, of course, direct consumption network.
    But for traditional items still have to manually import jar, use lib play with here.
    Here Insert Picture Description
    Here we can point to our own new lib directory, and can later be thrown into the jar where both. Select Jar Directory can be.

Here Insert Picture Description
After adding check on lib

3, edit the configuration Edit Configurations

Here Insert Picture Description

  • Tomcat配置
    如果是maven工程,可以配置maven自带的插件容器。
    核心是看下这个配置列表很有意思,Classes使用了如图两个jar,可以看到Tomcat具有jsp容器和servlet容器。
    我们可以想到,任何java程序都有一个main方法作为入口,负责启动和exit。
    那么这个方法就在tomcat中,并且servlet还是个调度程序,确保了处理所有请求启用一个系统进程和JVM实例。servlet是单例的。
    Here Insert Picture Description

  • 配置默认浏览器
    修改 Open browser 即可,还可以看到访问地址
    Here Insert Picture Description

  • 修改端口
    从上图可以看到,我们把http访问端口改成了10024,防止端口冲突。
    可以想象tomcat里面有个监听器,会根据实例持续占用某个端口,通过agent开发的经验看,基本都是一个死循环实现的,while(true)、for(;;)或者其他语言的死循环c。

  • 增加Before launch
    如增加一个build project
    这也就是很多同学说,为啥我java修改了,启动不生效的原因,因为启动没设置重新编译下。

  • 增加tomcat实例
    我这个IDEA工具也许N月前配置过tomcat,在setting里配置的所以可以直接使用,如果没有怎么办,例如没有maven,没有tomcat。
    如上图有个Template,可以在那里配置对应的工具,然后通过+号添加一个服务器实例即可。

  • VM parameters
    this is very important, because the real project is not helloworld, in accordance with the urine of the project is now possible to load the jar hundreds, and then open the thread pool to 10000, the memory can easily explode, so to set the tomcat jvm parameters correspond
    -Xms1024M - Xmx2048M -XX: PermSize = 128M -XX: MaxPermSize = 256M

  • Release configuration, specify the context

Here Insert Picture Description

Real project will have a limit Wengen, rarely used /, of course, in front of the access path to manually modify also:

Here Insert Picture Description

  • Labor successfully run again came out
    Here Insert Picture Description

summary

We still have to reflect on the next:

  • Tomcat in the end what role, which has a core part, respectively, what role?
  • IDEA and the eclipse is very different, the concept of a special project which include, respectively, what does this mean, and how to configure?
  • The first web project What's in part what external dependencies?
  • web.xml exactly how it works, what specific configurations, respectively, how to configure?
  • What the whole web of life cycle?

From the request to respond to the entire call chain, including the entire data transmission process, the data from the browser up to the transport layer how to go, and how to return to the browser?

  • Java Web's core technology is Servlet, from 2 to 4 versions of those differences?

The above problems, hope to Java Web really a complete review can be very clear understanding, that time frame does not matter, is the core API memory and understanding.

Go
Published 156 original articles · won praise 11 · views 5344

Guess you like

Origin blog.csdn.net/weixin_38280568/article/details/104048642