当前位置:网站首页>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
边栏推荐
- 读了一篇博客,重新理解闭包整理一下
- MySQL 修改主数据库
- Intégration de Clusters CDH Phoenix basée sur la gestion cm
- visio安装报错 1:1935 2:{XXXXXXXX...
- 全局变量能否放在头文件中定义
- Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
- Chapter I review of e-commerce spike products
- request模块
- PyMySQL
- leetcode--977. Squares of a Sorted Array
猜你喜欢
Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
JDBC入门
Subscription number development of wechat applet (message push)
Wechat applet positioning and ranging through low-power Bluetooth device (2)
更改plsql工具栏的图标大小
修改ddt生成的测试用例名称
微信小程序进行蓝牙初始化、搜索附近蓝牙设备及连接指定蓝牙(一)
PySide2
程序编译调试学习记录
帆软分割求解:一段字符串,只取其中某个字符(所需要的字段)
随机推荐
封装logging模块
帆软中单元格中隔行变色以及数量大于100字体变大变红设置
Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动
linux安装mysql后修改密码
DeepinV20安装Mariadb
groutine
Three point positioning based on ibeacons (wechat applet)
Oracle-数据泵使用
微信小程序获取登录用户信息、openid和access_token
JDBC入门
微信小程序setInterval定时函数使用详细教程
室内外地图切换(室内基于ibeacons三点定位)
Wechat applet input hidden and inoperable settings
基础知识学习记录
SPC简介
基于ibeacons三点定位(微信小程序)
jsp学习1
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
金蝶云星空API调用实践
微信小程序的订阅号开发(消息推送)