当前位置:网站首页>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
边栏推荐
- Day (2) of picking up matlab
- JS regular determines whether the port path of the domain name or IP is correct
- leetcode-396 旋转函数
- [self entertainment] construction notes week 2
- Jour (9) de ramassage de MATLAB
- 通过Feign在服务之间传递header请求头信息
- Filter usage of spark operator
- OAK-D树莓派点云项目【附详细代码】
- R语言中实现作图对象排列的函数总结
- Grbl learning (I)
猜你喜欢
Day (9) of picking up matlab
Gartner predicts that the scale of cloud migration will increase significantly; What are the advantages of cloud migration?
Day (5) of picking up matlab
捡起MATLAB的第(6)天
C language self compiled string processing function - string segmentation, string filling, etc
Coalesce and repartition of spark operators
JVM - Chapter 2 - class loader subsystem
homwbrew安装、常用命令以及安装路径
Spark 算子之distinct使用
299. Number guessing game
随机推荐
Win11/10家庭版禁用Edge的inprivate浏览功能
C language --- string + memory function
Fastjon2他来了,性能显著提升,还能再战十年
5 minutes, turn your excel into an online database, the magic cube net table Excel database
matplotlib教程05---操作图像
Passing header request header information between services through feign
How to conduct application security test (AST)
Intersection, union and difference sets of spark operators
一文掌握vscode远程gdb调试
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
力扣-198.打家劫舍
Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
MySQL - execution process of MySQL query statement
Fastjon2 here he is, the performance is significantly improved, and he can fight for another ten years
Matplotlib tutorial 05 --- operating images
What is cloud migration? The four modes of cloud migration are?
Spark 算子之groupBy使用
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
捡起MATLAB的第(5)天
JVM - Chapter 2 - class loader subsystem