当前位置:网站首页>JSP learning 2
JSP learning 2
2022-04-23 16:06:00 【If you believe】
1、 Built-in objects
<%@ page contentType="text/html; charset=UTF-8" pageEnconding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title> Built-in objects </title>
</head>
<body>
<%
String number="number";
pageContext.setAttribute("number",number);
//setAttribute Method to assign a value to the specified element attribute ,pageContext For built-in objects
%>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEnconding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title></title>
</head>
<body>
<%String u=(String)pageContext.getAttribute("number",number);%>
//getAttribute Method acceptance value
<%=u%>
<%--
out Method
out.print(); Output
--%>
<%
String a="528";
out.print(a);
%>
</body>
</html>
2、jsp Instructions
<%@ page contentType="text/html; charset=UTF-8" pageEnconding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title></title>
</head>
<body>
<%--
jsp Instructions :
Format :<%@ Instruction names Property name = Property value ......%>
1、page Instructions :
Example 1:<%@ page contentType="text/html; charset=UTF-8" pageEnconding="UTF-8" %>
pageEnconding And contentType Is to set the character set
The difference is :pageEnconding The default is text/html,contentType Can be set to other types
Example 2:import The attribute is import , You can call one of the methods
(1)<%@ page import="java.util.Date"%> Import util Under bag Date
(2)<%@ page import="java.util.*"%> Import util Everything under the bag
(3)<%@ page import="java.util.*,java.text.*"%> Import two at the same time , Separated by commas
Example 3:errorPage attribute , When an error occurs on the page, jump to the specified page
<%@ page errorPage="/error.jsp"%> The jump page can be customized , And add a slash in the dynamic
Example 4:isErrorPage attribute , Set whether to display the error type
<%@ page isErrorPage="true"%>
<body>
<%=exception.getMessage()%>// The page displays the error type
</body>
2、include Instructions :
Example 1: Will others jsp The content of the page is combined with the current page , Show it together
<body>
<%@ include file="/error.jsp"%>// take error.jsp The content of is displayed
</body>
Example 2:include Instructions can use the data transmitted from the page
stay error.jsp:
<body>
<%
String a="11";
%>
</body>
Use... On your current page include Instructions
<body>
<%@ include file="/error.jsp"%>
<%=a%>// Output error.jsp Medium a The value of the variable , Can output and use
</body>
Example 3:
stay error.jsp:
<body>
<%
out.println(b);
%>
</body>
Use... On your current page include Instructions
<body>
<%
String b="11";
%>
<%@ include file="/error.jsp"%>// Can output b The value of the variable
</body>
----------- Be careful : Cannot use... On the current page and include Instructions came from jsp The page defines the same variable name and different values , An error will be reported during output
--%>
</body>
</html>
版权声明
本文为[If you believe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231404212141.html
边栏推荐
- 腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
- Day (10) of picking up matlab
- Leetcode-374 guess the size of the number
- Spark 算子之distinct使用
- 力扣-746.使用最小花费爬楼梯
- Spark 算子之filter使用
- Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
- C language self compiled string processing function - string segmentation, string filling, etc
- Go language, condition, loop, function
- 面试题 17.10. 主要元素
猜你喜欢
安装Redis并部署Redis高可用集群
What is the experience of using prophet, an open source research tool?
Matplotlib tutorial 05 --- operating images
299. Number guessing game
TIA botu - basic operation
Gartner predicts that the scale of cloud migration will increase significantly; What are the advantages of cloud migration?
Day (7) of picking up matlab
Day (4) of picking up matlab
How important is the operation and maintenance process? I heard it can save 2 million a year?
volatile的含义以及用法
随机推荐
Config组件学习笔记
捡起MATLAB的第(4)天
Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
Accumulation of applet knowledge points
通过Feign在服务之间传递header请求头信息
Unity shader learning
Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant
JS regular determines whether the port path of the domain name or IP is correct
leetcode-396 旋转函数
Implement default page
How to upgrade openstack across versions
VIM specifies the line comment and reconciliation comment
安装Redis并部署Redis高可用集群
Ice -- source code analysis
捡起MATLAB的第(3)天
第九天 static 抽象类 接口
建设星际计算网络的愿景
R语言中绘制ROC曲线方法二:pROC包
实现缺省页面
C, calculation method and source program of bell number