当前位置:网站首页>JSP entry notes
JSP entry notes
2022-06-23 05:08:00 【Don't want to be a programmer】
JSP
1、 What is? JSP
Java Server Pages:Java Server side page , And also Servlet equally , For dynamic Web technology
The biggest feature :
- Write JSP It's like writing HTML
- difference :HTML Only static data is provided to users 、jsp Pages can embed JAVA Code , Provide users with dynamic data
2、JSP principle
Ideas :JSP How did it happen
- There are no problems at the code level
- Work inside the server
tomcat There is one of them. work Catalog ;
IDEA Use Tomcat Of will be in IDEA Of Tomcat To create a work Catalog
Browser sends request to server , No matter what resources are accessed , In fact, they are all visiting Servlet!
JSP It will eventually be transformed into a Java class !
JSP It's essentially one Servlet
// initialization
public void_jspInit(){
}
// The destruction
public void_jspDestory(){
}
//JSPService
public void _jspService(.HttpServletRequest request,HttpServletResponse response){
}
- Judge the request
- Built in some objects

- All of the above can be found in jsp Use in !
stay JSP On the page :
As long as it is JAVA The code will be output intact ;
If it is HTML Code , It will be converted to :<out.write("<html>\r\n")> This format is output to the front end !
3、JSP Basic grammar
Every language has its own grammar ,JAVA There is ,.
JSP expression
<%--JSP expression
effect : Used to convert the output of the program , Output to client
<%= Variables or expressions %>
--%>
<%= new java.util.Date()%>
JSP Script
<%
int sum = 0;
for(int i = 1;i<=100;i++){
sum+=i;
}
System.out.println("<h1>Sum="+sum+"</h1>");
%>
JSP Statement
<%!
static{
System.out.println(" Statement ");
}
private int globalVar = 0;
%>
JSP Statement : Will be compiled into JSP Generate Java In the two-point class ! Other , Will be generated to _jspService In the method !
<%@ page import="java.util.*"%>
<%@ page isErrorPage="true" %> // This is an error page
<%@ page errorPage="error.jsp" %> // If it is an error page, go to error.jsp
web.xml Add the configuration error page 
4、9 Large built-in objects
- PageContext To save things
- Request To save things
- Response
- Session To save things
- Application【ServletContext】 To save things
- config【ServletConfig】
- out
- page
- exception
JSP Page code
<%
pageContext.setAttribute("name","jjj");// The saved data is only valid in one page
request.setAttribute("name2","jjj2");// The saved data is only valid in one request , Request forwarding will carry this data
session.setAttribute("name1","jjj1");// The saved data is valid only in one session , From open browser to close browser
application.setAttribute("name3","jjj3");// The saved data is only valid in the server , From turning on the server to turning off the server
%>
<% pageContext.setAttribute("hello1","hello1",PageContext.SESSION_SCOPE);%>// Equate to
<%--<% session.setAttribute("hello1","hello1");%>--%>
request: Client sends request to server , Data generated , It is useless after reading with the user , such as : Journalism , It's useless for the user to read !
session: Client sends request to server , Data generated , After the user runs out, there are still , such as : The shopping cart ;
application: Client sends request to server , Data generated , One user ran out , Other users may also use , Such as chat data
5、JSP label 、JSTL label 、EL expression
EL expression :(${ })
- get data
- Perform an operation
- obtain web Common objects for development
<jsp:forward page=" index.jsp">
<jsp:param name="value1" value="value1"></jsp:param>
<jsp:param name="value2" value="value2"></jsp:param>
</jsp:forward>`// Jump to a page
// Take out the parameters
<%= request.getParam("value1")%>
<%= request.getParam("value2")%>
JSTL label
Rookie course study
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
JSTL The tag library is to make up for HTML The lack of labels ; It customizes many labels .
Core tags ( Master part ):
Format label :
xml label
Use steps :
- Introduce the corresponding taglib
- Use the method
- stay Tomcat We also need to introduce jstl package , Otherwise, an error will be reported :JSTL Parse error (Tomcat Of lib in )
<form action="coreif.jsp" method="get">
<input type="text" name="value1" value="${param.value1}">
// Determine if the submitted user is an administrator , Login succeeded
<c:if test="${param.value1=='value1'}" var="isAdmin">
<c:out value=" The administrator welcomes you !">
</c:if>
// Self closing label
<c:out value="$(idAdmin)"/>
<c:set var="score" value="85"/>
<:choose>
<c:when test="${score>90}">
You have to do well
</c:when>
<c:when test="${score>=80}">
You have to do well
</c:when>
<c:when test="${score>=70}">
Your grades are average
</c:when>
<c:when test="${score<=60}">
You have to fail
</c:when>
</c:choose>
//var Every time you traverse the variables
//items Object to traverse
//begin Where to start
//end Where to end
//step step
<c:forEach var="***" items = ${
list}>
<c:out value="${people}"/><br>
</c:foreach>
<c:forEach var="" items="" begin="" end="" step=""></forEach>
边栏推荐
- [C language] keyword
- ICER skill 02makefile script self running VCs simulation
- Wechat applet example development: run
- Brief ideas and simple cases of JVM tuning - why do you need JVM tuning?
- [paper reading] semi supervised learning with ladder networks
- 微信小程序:拼图工具箱
- MySQL import large files (can be millions or hundreds)
- MVC三層架構
- 传统意义上的互联网式的平台或将不复存在,一个融合的产业特质和互联网特质的全新产业
- How to make social media the driving force of cross-border e-commerce? This independent station tool cannot be missed!
猜你喜欢

dolphinscheduler 1.2.1 数据迁移到 dolphinscheduler 2.0.5方法及迁移后数据测试记录

【图论】—— 二分图

TabControl style of WPF basic control

Abnova fluorescent dye 510-m streptavidin scheme

go学习记录二(Window)

代码片段管理器SnippetsLab

PRCS-1016 : Failed to resolve Single Client Access Name

ICER skill 02makefile script self running VCs simulation

【Proteus仿真】Arduino UNO+PCF8574+LCD1602+MPX4250电子秤
![[paper reading] semi supervised learning with ladder networks](/img/c9/e2f4b221d762f41ba6b75926293673.png)
[paper reading] semi supervised learning with ladder networks
随机推荐
The solution to prompt "this list creation could be rewritten as a list literal" when adding elements to the list using the append() method in pychart
ICer技能02makefile脚本自跑vcs仿真
Usage of apipost interface test ------ get
Abnova fluorescent dye 555-c3 maleimide scheme
Dolphin scheduler 2.0.5 spark task test summary (source code optimization)
微信小程序实例开发:跑起来
功能测试人员如何做到花一个月的时间进阶自动化软件测试工程师
What are the main aspects of visual improvement brought by introducing AI into ISP Technology
Abnova liquidcell negative enrichment cell separation and recovery system
AlertManager告警的单独使用及prometheus配置告警规则使用
② Cocoapods principle and podspec file uploading operation
Cloud native database is in full swing, and the future can be expected
当SBAS遇上rtklib
MVVM has become history, and Google has fully turned to MVI
[C language] keyword
ICER skills 03design compile
Thinkphp6 solving jump problems
dolphinscheduler 2.0.5 spark 任务测试总结(源码优化)
Automatically add watermark to screenshot
微信小程序:土味情话恋爱话术