当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
jacob打印word
收藏博客贴
Chrome插件 之 Selenium IDE、XPath 安装
MYSQL 主从同步避坑版教程
生产环境——
基於CM管理的CDH集群集成Phoenix
SQL: How to parse Microsoft Transact-SQL Statements in C# and to match the column aliases of a view
百度图片识别自定义实现(替代AipOcr)
gzip和gunzip 解压参数详解
基于ibeacons三点定位(微信小程序)
Idea控制台乱码解决
log4j 输出日志信息到文件中
不同时间类型的执行计划计算
帆软中需要设置合计值为0时,一整行都不显示的解决办法
Promtail + Loki + Grafana 日志监控系统搭建
微信小程序的订阅号开发(消息推送)
Wechat applet communicates with esp8266 based on UDP protocol
微信小程序获取登录用户信息、openid和access_token
容差分析相关的计算公式
对List集合进行分页







