当前位置:网站首页>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 (6) of picking up matlab
捡起MATLAB的第(9)天
MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
运维流程有多重要,听说一年能省下200万?
Government cloud migration practice: Beiming digital division used hypermotion cloud migration products to implement the cloud migration project for a government unit, and completed the migration of n
299. 猜数字游戏
Meaning and usage of volatile
Implement default page
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
C language --- advanced pointer
随机推荐
JS regular détermine si le nom de domaine ou le chemin de port IP est correct
捡起MATLAB的第(6)天
linux上启动oracle服务
面试题 17.10. 主要元素
Config learning notes component
Tencent offer has been taken. Don't miss the 99 algorithm high-frequency interview questions. 80% of them are lost in the algorithm
Grbl learning (II)
Vision of building interstellar computing network
第十天 异常机制
ESP32_Arduino
Master vscode remote GDB debugging
Spark 算子之coalesce与repartition
【第5节 if和for】
Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
Coalesce and repartition of spark operators
实现缺省页面
Spark 算子之交集、并集、差集
dlopen/dlsym/dlclose的简单用法
The system research problem that has plagued for many years has automatic collection tools, which are open source and free
leetcode-374 猜数字大小