当前位置:网站首页>JSP学习2
JSP学习2
2022-04-23 14:05:00 【你若信】
1、内置对象
<%@ 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 number="number";
pageContext.setAttribute("number",number);
//setAttribute方法为指定的元素属性赋值,pageContext为内置对象
%>
</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方法接受值
<%=u%>
<%--
out方法
out.print();输出
--%>
<%
String a="528";
out.print(a);
%>
</body>
</html>
2、jsp指令
<%@ 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指令:
格式:<%@ 指令名称 属性名=属性值 ......%>
1、page指令:
例子1:<%@ page contentType="text/html; charset=UTF-8" pageEnconding="UTF-8" %>
pageEnconding与contentType都是设置字符集
不同的是:pageEnconding默认是text/html,contentType可以设置成其他类型
例子2:import属性为导入,就可以调用其中的方法
(1)<%@ page import="java.util.Date"%>导入util包下的Date
(2)<%@ page import="java.util.*"%>导入util包下的所有
(3)<%@ page import="java.util.*,java.text.*"%>同时导入两个,以逗号隔开
例子3:errorPage属性,当页面发生错误时跳转到指定页面
<%@ page errorPage="/error.jsp"%> 其中跳转的页面可以自定义,且在动态中加斜杠
例子4:isErrorPage属性,设置是否显示错误类型
<%@ page isErrorPage="true"%>
<body>
<%=exception.getMessage()%>//页面中显示错误类型
</body>
2、include指令:
例子1:将其他jsp页面的内容与当前的页面组合,一起显示出来
<body>
<%@ include file="/error.jsp"%>//将error.jsp的内容显示出来了
</body>
例子2:include指令可以能使用页面传过来的数据
在error.jsp:
<body>
<%
String a="11";
%>
</body>
在自己的当前页面用include指令
<body>
<%@ include file="/error.jsp"%>
<%=a%>//输出error.jsp中的a变量的值,可以输出和使用
</body>
例子3:
在error.jsp:
<body>
<%
out.println(b);
%>
</body>
在自己的当前页面用include指令
<body>
<%
String b="11";
%>
<%@ include file="/error.jsp"%>//可以输出b变量的值
</body>
-----------注意:不能在当前页面和用include指令传过来的jsp页面定义相同的变量名且值不一样,输出时会报错
--%>
</body>
</html>
版权声明
本文为[你若信]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44152890/article/details/123940517
边栏推荐
猜你喜欢
基于CM管理的CDH6.3.2集群集成Atlas2.1.0
scikit-learn构建模型的万能模板
Pytorch 经典卷积神经网络 LeNet
帆软中单元格中隔行变色以及数量大于100字体变大变红设置
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
Neuron and neural network
MYSQL 主从同步避坑版教程
Subscription number development of wechat applet (message push)
Autumn recruitment in 2021, salary ranking No
Prediction of tomorrow's trading limit of Low Frequency Quantization
随机推荐
Chapter 15 new technologies of software engineering
CentOS mysql多实例部署
微信小程序获取登录用户信息、openid和access_token
基于CM管理的CDH6.3.2集群集成Atlas2.1.0
mysql新表,自增id长达20位,原因竟是......
VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
groutine
Check in system based on ibeacons
修改ddt生成的测试用例名称
Autumn recruitment in 2021, salary ranking No
Use of WiFi module based on wechat applet
Jmeter安装教程以及我遇到的问题的解决办法
SPC简介
Detailed tutorial on the use of setinterval timing function of wechat applet
Pycharm连接远程服务器并实现远程调试
Redis docker 安装
关于stream流,浅记一下------
更改plsql工具栏的图标大小
微信小程序的订阅号开发(消息推送)
org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su