当前位置:网站首页>Half an hour to understand JSP
Half an hour to understand JSP
2022-04-22 11:07:00 【Huai Ye】
Catalog
JSP and Servlet The difference between
(1) Why? jsp The first access to the file is slow ?
(2)JSP The extension of must be xxx.jsp Do you ?
JSP summary
JSP yes java Program , yes JavaServer Pages Abbreviation .( be based on Java Language implementation of the server-side page )
JSP It's a set of norms . be-all web Containers /web Servers follow this set of specifications , every last web Containers /web The server will have a built-in JSP Translation engine .
Yes JSP When debugging errors , To open it directly JSP File corresponding java file , Check java Code .
JSP If you don't understand , Make a proposal to jsp Translate into java Code , You can read it .
JSP The essence
JSP It's essentially a Servlet
index.jsp At the time of the visit , Will automatically translate and generate index_jsp.java, Will automatically compile and generate index_jsp.class, that index_jsp It's a class .
index_jsp Class inheritance HttpJspBase, and HttpJspBase Class inherits HttpServlet. therefore index_jsp A class is just a Servlet class .
- jsp The life cycle of Servlet The life cycle of is exactly the same .
- jsp and servlet equally , It's all singletons .( False single case )
JSP and Servlet The difference between
Different responsibilities
- Servlet: collecting data ( Logical processing , Business processing , Then connect to the database , obtain / collecting data )
- JSP: Display data
JSP Basic grammar of
1. stay jsp Write text directly in the document , Will be automatically translated to where ?
Translate to servlet Class service Methodical out.write(" Translate here "), Translate directly into double quotation marks , By java The program prints out to the browser as an ordinary string .
stay JSP Writing in the HTML,CSS,JS Code , These codes are for JSP It's just an ordinary string . however JSP Once this ordinary string is output to the browser , The browser will respond to HTML,CSS,JS To interpret and execute , To show an effect .
2.page Instructions
(1) Chinese garbled code in response :
adopt contentType Property is used to set the content type of the response , Add... At the end of the content type :charset=UTF-8
<%@page contentType="text/html;charset=UTF-8"%>
The content type of the response is text/html, Adopted character set UTF-8
(2) Guide pack
<%@page import="java.util.List,java.util.ArrayList"%>
3. stay JSP Written in Java Program :
(1)<% java sentence ; %>
- What is written in this symbol is considered java Program , Translated to Servlet Class service Methods the internal .
- stay <% %> This symbol says java Code time , You should always remember that you are “ Method body ” Write code in it , What can be written in the method body , You can't write anything ?
- service Static code blocks cannot be written in methods , Cannot write method , Member variables cannot be defined
- The code in the method body should be executed line by line from top to bottom .
- In the same JSP among <%%> This symbol can appear more than one .
(2)<%! %>
- Written in this symbol java The program will automatically translate to service Out of the way .
- Not recommended , Because in service Write static variables and instance variables outside the method , There will be thread safety problems .servlet Is a singleton , Multithreading concurrent environment , Once the static variable and instance variable are modified , There must be thread safety issues .
4.JSP The output statement of
(1) Output a... To the browser java Variable
<%
String name = “Tom”;
out.write("name = " + name);
%>
out yes JSP One of the nine built-in objects . Can be directly in service Method used internally
(2) If there is no... In the output to the browser java Code , For example, output a fixed string , Can be directly in jsp Written in , There is no need to write <%%> here .
(3) If the output contains java Code
<%= %>
- stay = Write the content to be output after .
- Will translate to service Among the methods , It's this java Code :out.print();
5.JSP Notes
(1)<%--JSP Professional notes , Will not be translated into java In the source code .--%>
(2)<!-- Belong to HTML Notes , The annotation information will still be translated into java In the source code , Don't suggest .-->
Digression
(1) Why? jsp The first access to the file is slow ?
Most o & M personnel demonstrate the project to customers , I'll put all the... In advance jsp Access the file first .
for the first time :
- To put jsp File translation generation java Source file
- java The source file should be compiled to generate class Bytecode file
- And then through class To create servlet object
- And then call servlet Object's init Method
- Last call servlet Object's service Method .
The second time is faster
Call the singleton directly servlet Object's service The method can .
(2)JSP The extension of must be xxx.jsp Do you ?
jsp The extension of the file can be configured . Not fixed .
stay CATALINA_HOME/conf/web.xml, Configure... In this file jsp Extension of the file .
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
xxx.jsp File for Tomcat Come on , Just an ordinary text file ,web The container will xxx.jsp Final file generation java Program , The final call is java Object related methods , When it's actually implemented , and jsp The document doesn't matter .
版权声明
本文为[Huai Ye]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221103125974.html
边栏推荐
- vulnhub The Planets: Earth
- Analysis of module d electronic answer card of "network security" (secondary vocational group) in 2022 skill competition - new vulnerabilities
- CISSP certified daily knowledge points (April 20, 2022)
- 2022 年度广东省职业院校学生专业技能大赛网络安全(中职组)赛项样题
- mysql-prepare用法
- ADB 命令知多少?详细 ADB 命令大全来啦
- 图解文件系统——我见过讲文件系统讲的最好的文章了
- Robot system design coppeliasim simulation
- C language advanced level 1 ------ "data storage (original code inverse code complement + size end judgment + integer promotion + floating point number storage)
- Secondary vocational network security D - file upload
猜你喜欢

Interface normative test standard specification - detailed

在安装mySQL出现这种问题如何解决呢?

观测云入驻阿里云计算巢,为用户构建稳定安全的云上连接

大家都在努力,你凭什么不努力

MySQL installation summary

关于正则表达式匹配密码问题

Create object memory analysis and inheritance

Best practices of Apache APIs IX high availability configuration center based on tidb

Ampere computing releases the computing power of observation cloud "core" and jointly promotes the development of observability

Fundamentals of machine learning
随机推荐
CVPR 2022 | 用Transformer学习多假设表示!3D人体姿态估计的新框架!
【数据挖掘】用Excel挖掘股权关系并按照年份统计不同类型的亲缘关系在上市公司中的分布和趋势【可视化呈现】
点击tab栏如何让tab置顶
Redis login client command
Sample questions of 2022 Guangdong Vocational College Students' professional skills competition network security (secondary vocational group)
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
Synchronized lock and its expansion
js获取dom元素宽高
半小时理解JSP
Batch update software and security optimization (taking openssh as an example) -- the road of building a dream
链表动态头插法
Everyone is trying. Why don't you try
找国企、央企、上市公司投资人,我选择塔米狗!
Ampere Computing释放观测云“芯”算力,强强联合推动可观测性发展
Redis 环境安装
Postman interface testing tool video tutorial, zero basic entry to master graduation
2022渗透岗位面试(思路篇)
Synchronized lock and its expansion
Qdebug() print debugging information
三六零发布年报:实现营业收入约108.86亿元 安全业务增长超70%