当前位置:网站首页>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
边栏推荐
- Go language, condition, loop, function
- Spark 算子之groupBy使用
- 多线程原理和常用方法以及Thread和Runnable的区别
- How can poor areas without networks have money to build networks?
- Algorithem_ ReverseLinkedList
- Groupby use of spark operator
- 运维流程有多重要,听说一年能省下200万?
- New developments: new trends in cooperation between smartmesh and meshbox
- Nanny Anaconda installation tutorial
- 实现缺省页面
猜你喜欢

Use bitnami PostgreSQL docker image to quickly set up stream replication clusters

Spark 算子之distinct使用

R语言中绘制ROC曲线方法二:pROC包

建设星际计算网络的愿景

Cloud migration practice in the financial industry Ping An financial cloud integrates hypermotion cloud migration solution to provide migration services for customers in the financial industry

一文读懂串口及各种电平信号含义

Using JSON server to create server requests locally

捡起MATLAB的第(8)天

How to upgrade openstack across versions

OAK-D树莓派点云项目【附详细代码】
随机推荐
leetcode-374 猜数字大小
ESP32_ Arduino
Grbl learning (II)
捡起MATLAB的第(9)天
TIA botu - basic operation
Passing header request header information between services through feign
Pgpool II 4.3 Chinese Manual - introductory tutorial
Spark 算子之sortBy使用
JS regular détermine si le nom de domaine ou le chemin de port IP est correct
Cloudy data flow? Disaster recovery on cloud? Last value content sharing years ago
Day (10) of picking up matlab
如何进行应用安全测试(AST)
Intersection, union and difference sets of spark operators
[self entertainment] construction notes week 2
Nanny Anaconda installation tutorial
Day (5) of picking up matlab
[split of recursive number] n points K, split of limited range
Implement default page
Coalesce and repartition of spark operators
How do you think the fund is REITs? Is it safe to buy the fund through the bank