当前位置:网站首页>JSP初识
JSP初识
2022-07-25 21:50:00 【华为云】
目录
JSP简介
jsp的全称是java server pages 。java的服务器页面。
jsp的主要作用是替代Servlet程序回传html页面的数据。
因为Servlet程序回传html页面数据是一件非常繁琐的事情,不利于开发和维护。
jsp的创建
jsp如何访问
jsp页面和html一样,都是存放在web目录下。访问也跟html页面一样。
如:web目录下的文件
a.html页面:http://ip:port/工程路径/a.html
b.jsp页面:http://ip:port/工程路径/b.jsp
jsp的本质
jsp的本质是一个servlet程序
当我们第一次访问服务器时,tomcat会把jsp页面翻译成一个java源文件,并且对他编译成为.class的字节码程序
字节码文件就是对应的java源文件,打开源文件可以发现
b_jsp这个类继承了HttpJspBase类,我们通过idea发现HttpJspBase类直接继承了HttpServlet类,所以说,jsp翻译出来的java类间接继承了HttpServlet类,所以说,jsp实质为Servlet程序
观察翻译出来Servlet源代码可以发现,低层也是通过输出流来把html页面回传给客户端的。
jsp头部的page指令
jsp的page指令可以修改jsp页面中一些重要的属性,或者行为。
常见属性:
language属性 表示jsp翻译后什么语言文件,暂时只能支持Java。
contentType属性 表示jsp返回的数据类型是什么,在源码中response.setContentType()参数值
pageEncoding属性 表示当前jsp页面文件本身的字符集。
import属性 跟java源代码中一样用于导包,导类。如:
autoFlush属性 设置当out输出流缓冲区满了之后,是否自动刷新缓冲区,默认true。
buffer属性 设置out缓冲区的大小,默认是8kb
当我们设置不自动刷新缓冲区,且设置的缓冲比较小时就会发生jsp溢出,如果设置了自动刷新就不会溢出。(缓冲区设置8kb是综合最佳的)
errorPage属性 设置当jsp页面运行时出错,自动跳转去的错误页面路径
errorPage表示错误后自动跳转去的路径,这个路径一般是以斜杆开头,他表示请求地址为http://ip:port/工程路径/,映射到代码中的web目录
b.jsp页面如下:
isErrorPage属性 设置当前jsp页面是否·错误信息页面,默认是false,如果是true可以获取异常信息。
session属性 设置访问当前jsp页面,是否会创建HttpSession对象,默认是true。
extends属性 设置jsp翻译出来的java类默认继承谁
边栏推荐
- C语言游戏 双缓存解决闪屏问题 详细总结[通俗易懂]
- strcpy()
- Detailed explanation of JVM memory model and structure (five model diagrams)
- Come again
- LeetCode_ 93_ Restore IP address
- I/O案例实操
- I'm also drunk. Eureka delayed registration and this pit!
- PE format: analyze and implement IATHOOK
- 【Redis底层解析】链表类型
- 8000 word super detailed custom structure type
猜你喜欢

New maixhub deployment (v831 and k210)

新版Maixhub部署(V831与K210)

Vivo official website app full model UI adaptation scheme

2022最新软件测试八股文,能不能拿心仪Offer就看你背得怎样了

PE format: analyze and implement IATHOOK

ansible+Crontab批部署巡检

GPON introduction and Huawei OLT gateway registration and configuration process

少儿编程 电子学会图形化编程等级考试Scratch一级真题解析(判断题)2022年6月

Why do independent sellers like to do e-mail marketing? The original conversion rate can be improved so much!
![[interview: concurrent Article 23: multithreading: Join] re understanding of join](/img/ee/5160a55e776336ba844abe8e9db72a.png)
[interview: concurrent Article 23: multithreading: Join] re understanding of join
随机推荐
strcpy()
若依如何解决导出使用下载插件出现异常?
选择的能力
New maixhub deployment (v831 and k210)
Tesseract OCR初探
At present, flynk CDC does not support mysql5.5. If you change the source code and release this restriction, there will be a lot of data problems?
zigbee开发板(nxpzigbee开发)
[database] conceptual design, logical design, relational database design theory
Composition of dog food
[ManageEngine] value brought by Siem to enterprises
mysql8.0 mha实现高可用《mha》
Automatic assembly and fuse degradation of feign
How to configure and use rocksdb in the flinksql environment
Dear bosses, how can I print the result of Flink SQL to the console and display it completely?
Interviewer of large factory: how to quickly query a table with tens of millions of data?
Basic knowledge in the project
Babbitt | metauniverse daily must read: the popularity of virtual people has decreased, and some "debut is the peak", and the onlookers have dispersed
dovecot 设置邮箱quota
Ability to choose
少儿编程 电子学会图形化编程等级考试Scratch一级真题解析(判断题)2022年6月





