table of Contents
Chapter One: Recognizing server
1.1 What is a server
In short, the server software is installed high with the electronic device (computer)
The role Server Software 1.2
Receiving a client's request, process the request , make a response .
Web Server: is the web container, you can deploy the Web project to the server, allows users to access resources on the server browser.
- Static resources: html, css, js series of documents the content, when accessed, can directly transfer content network.
- Dynamic Resources: jsp / php / asp, etc., when accessed, you need to convert a static resource, and then transmitted.
1.3 common server software
- webLogic: oracle company, large JavaEE server, supports all the JavaEE specification, for a fee.
- webSphere: IBM Corporation, a large JavaEE server, supports all the JavaEE specification, for a fee.
- JBOSS: JBOSS company's large JavaEE server, supports all the JavaEE specification, for a fee.
- Tomcat : the Apache Fund, small and medium JavaEE server, supports only a small number of JavaEE specification servlet / jsp. Open source, free of charge.
Chapter II: Tomcat
2.1 install, uninstall, start
download
Address: https://tomcat.apache.org
installation
For downloading the installation package, extract to the specified directory.
Uninstall
Delete unzipped directory.
After installation directory
start up
Enter bin
the directory executionstartup.bat
access:
- http: // localhost: 8080 Enter access to your
- http://ip地址:8080 访问别人
启动可能遇到的问题1:
- 问题:黑窗口一闪而过
- 原因:没有正确配置JAVA_HOME环境变量
- 解决方案:正确配置JAVA_HOME环境变量
启动可能遇到的问题2:
问题:启动报错
原因:端口号可能冲突
解决方案:
暴力解决:通过DOS命令
netstat -ano
,找到端口号被占用的程序的PID,然后在任务进程中根据PID找到程序,结束进程。更改端口号:找到conf目录中的server.xml
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8445" /> <!-- 一般会将tomcat的默认端口号修改为80。80端口号是http协议的默认端口号。 若改为80端口号时,在访问时,就不用输入端口号 -->
关闭
- 正常关闭:
- 进入bin目录中双击执行shutdown.bat
- 在启动的窗口中ctrl + c
- 强制关闭:点击关闭按钮
2.2-部署静态资源
方式1:
直接将项目放到webapps目录下即可。
简化部署:将项目打成一个war包,再将war包放置到webapps目录下。war包会自动解压缩
部署完成后访问:http://localhost/jdWeb/index.html
方式2:
配置conf目录下的server.xml文件
<!--在`<Host>`标签体中配置-->
<Context docBase="D:\jdWeb" path="/jd" />
<!--
docBase:项目存放的路径
path:虚拟目录
-->
部署完成后访问:http://localhost/jd/index.html
方式3
在conf\Catalina\localhost
创建任意名称的xml文件。在文件中编写
如以下文件:jd.xml,文件名就是虚拟路径。
<Context docBase="D:\jdWeb" />
部署完成后访问:http://localhost/jd/index.html
2.3-将Tomcat集成到IDE中
步骤1:打开IntelliJ IDEA开发工具
步骤2:点击窗口工具run
下的Edit Configurations
步骤3:选择本地tomcat目录关联到IDE中
2.4-在IDE中创建JavaEE项目
新建项目,并做如下操作:
2.5-JavaEE项目目录结构
- 根目录
- WEB-INF目录
- web.xml,项目的核心配置文件
- classes目录,放置字节码文件的目录
- lib目录,放置依赖jar包的目录
- WEB-INF目录
2.6-更改项目的虚拟目录
步骤1 :
步骤2: