1.JSP: Dynamic web pages
Static, dynamic:
1) do not and whether there is "dynamic" confused
2) whether over time, change the location, user operations change.
3) dynamic web page need to use server-side scripting languages (JSP)
2. Web Application Architecture
B / S (brower / Server) server browser
Clients can directly access the server through a browser
Advantages: convenient, do not download, update, maintenance upgrades simple, cross-platform.
C / S (Client / Server) client server
Disadvantages:
. a If the software upgrade, the software needs to be upgraded all the
b maintenance problems: the need to maintain each client software
c each client need to install client software.
Advantages: sharing bear part of the computational server
3.tomcat download and configuration
First go to tomcat official website to download tomcat, into the tomcat's official website after the left there is a downloadable version of tomcat
After selecting here download Tomcat8 version, click on the Tomcat 8, have the right to download a different version of the system
Here are classified by kinds tomcat 3 download, windows version installed version of tomcat, non-install version of tomcat, as well as linux system.
zip is a universal system, Windows and Linux systems can be used.
tar.gz is dedicated Linux system.
32-bit windows zip-bit system is Windows32 specific.
64-bit windows zip-bit system is Windows64 specific.
32-bit / 64-bit Windows Service installer is Windows32 / 64-bit installation version tomcat, 4 Species above all non-mounting plate.
Here I chose to download the 64-bit non-install version of tomcat configure, install version of tomcat tutorial click here: install version tomcat configuration .
下载完后把tomcat压缩包解压,然后选择你要存放的路径。
然后打开bin目录选择startup.bat运行tomcat服务器
注意,运行tomcat服务器后,命令窗不能关掉,关掉等于关闭了tomcat服务器,只能最小化,或者使用安装版tomcat。
安装版的tomcat可以使用bin目录下的运行tomcat服务器,不需要借助命令窗来执行。
补充:如果双击startup.bat直接闪退,可能是JAVA_HOME的环境变量没有配置好又或者是端口冲突,tomcat服务器依赖jdk运行,tomcat运行时自动寻找JAVA_HOME的环境变量。
如果配置了JAVA_HOME但是还是闪退,只能去配置tomcat的CATALINE_HOME环境,CATALINE_HOME的作用是指定找到JAVA_HOME的环境变量。
配置好后,打开tomcat服务器进行测试是否配置成功,在浏览器的地址栏输入:localhost:8080,就会出现下图。
注意tomcat默认端口是8080,我这里修改了端口为80,80端口可以不用填进去,80端口默认添加,如果想修改端口号,如下
找到tomcat目录下的conf目录,这里是配置文件目录,打开server.xml文件
打开文件后,然后快捷键ctrl+f寻找port端口
然后就可以修改端口号了,修改完成后,保存,重启tomcat服务器后生效。
补充访问地址时的常见状态码:
常见状态码:
200:一切正常
300/301: 页面重定向 (跳转)
404:资源不存在
403:权限不足 (如果访问a目录,但是a目录设置 不可见)
500:服务器内部错误(代码有误)
其他编码:积累
4.创建jsp项目测试
首先在tomcat的webapps目录下创建项目文件夹
基本的jsp项目包含WEB-INF目录和jsp文件
而WEB-INF文件夹可以去root目录里面复制
复制以后,WEB-INF里面必须包含:
classes文件夹存放字节码文件,jsp->java->class编译。最后把class文件存放到classes目录
lib文件夹存放jar包
web.xml这个是默认需要的文件。
然后WEB-INF文件夹里面创建classes文件夹和lib文件夹,web.xml就不用了,因为复制过来的时候就存在了。
然后返回到jspProject目录,创建测试的jsp文件
创建txt文件,然后把后缀改为jsp
然后打开jsp文件,在里面创建测试代码
<html> <head> <title>my jsp project</title> </head> <body> hello jsp... <% out.print("hello world..."); %> </body> </html>
<% 内容 %> 这是jsp代码的编写方式,在里面编写jsp代码。
然后打开tomcat服务器,会自动运行项目,因为jspProject项目已经在webapps里面了,tomcat运行,会自动运行webapps里面的项目
测试成功,注意浏览器的地址访问目录不要写错。
补充:地址栏为什么没有加上index.jsp呢,因为web.xml里面默认声明会去寻找index.jsp文件。
可以在web.xml里面显式声明首选访问哪个页面,从上面往下的顺序。
比如你创建了一个index2.jsp的文件,则需在web.xml里面添加
<welcome-file-list> <welcome-file>index2.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list>
则会在访问jspProject项目时,即使没有指定访问哪个文件,会根据上面指定的文件顺序去寻找文件访问。
tomcat基本配置已经结束。