当前位置:网站首页>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类默认继承谁
边栏推荐
- NVIDIA has opened source a comprehensive library of 3D deep learning based on pytorch
- Naming rules for BSP of Quanzhi chip
- I/o case practice
- [redis underlying parsing] linked list type
- QT | learn about QT creator by creating a simple project
- Dovecot set mailbox quota
- MySQL master-slave configuration
- 狗粮的成分
- C common set
- Idea resolves the prompt of profile properties disappear
猜你喜欢

Bitcoin.com:USDD代表了真正去中心化稳定币

The adequacy of source evaluation forum · observation model test

Bitcoin.com:usdd represents a truly decentralized stable currency

Creation and destruction of function stack frames
![[interview: concurrent Article 23: multithreading: Join] re understanding of join](/img/ee/5160a55e776336ba844abe8e9db72a.png)
[interview: concurrent Article 23: multithreading: Join] re understanding of join

Performance debugging -- chrome performance

I'm also drunk. Eureka delayed registration and this pit!

Optimization analysis of storage structure and IO performance of openharmony littlefs file system

Job interviews are always a second kill? After reading the seckill system notes secretly stored by JD T8, I have given my knees

函数栈帧的创建和销毁
随机推荐
Special symbols in shell
我也是醉了,Eureka 延迟注册还有这个坑!
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
【测开方法论】测开平台pk心得-抉择
[leetcode ladder] linked list · 021 merge two ordered linked lists
golang : MVC之models
Ijcai2022 meeting! Microsoft and other tutorials on domain generalization
C语言游戏 双缓存解决闪屏问题 详细总结[通俗易懂]
ORIGYN基金会正式启动$OGY Staking,引领新一轮生态利好
[hand tear STL] BitSet (bitmap), bloom filter
ansible+Crontab批部署巡检
【Redis底层解析】链表类型
Bitcoin.com:USDD代表了真正去中心化稳定币
5、 Pinda general permission system__ PD tools XXS (anti cross site script attack)
Zero basic learning canoe panel (17) -- panel CAPL function
Create files, file permissions, ownership, and sticky bits
The noise reduction effect is increased by more than 6 times! With the microphone inside the headset, this wireless noise reduction headset is unusual!
H5 realize the animation effect of a scratch card
文件无法保存(文件夹已损坏无法读取怎么办)
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)





