当前位置:网站首页>jsp学习3
jsp学习3
2022-04-23 14:05:00 【你若信】
1、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动作:
格式:<jsp:动作名称 属性名=属性值 属性名=属性值......></jsp:动作名称>
1、forward动作
例子:当前页面
<body>
帅哥<br>
<jsp:forward page="/net.jsp"></jsp:forward>
</body>
在net.jsp中
<body>
美女
</body>
结果页面只输出了美女,而没有输出帅哥
2、include动作
例子:当前页面
<body>
帅哥<br>
<jsp:include page="/net.jsp"></jsp:include>
<%=a%>//会报错
</body>
在net.jsp中
<body>
美女<br>
<%
String a="11";
%>
</body>
结果页面输出了帅哥美女,而没有输出a
--%>
</body>
</html>
2、EL表达式(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>
<%--
EL表达式:只能从四大域中获取数据,且不能赋值
用${
}可以获取值,并显示出来
例子1:<body>
<%
String user="11";
%>
user=${
user}
</body>
结果:user= 没有user的值
例子2:<body>
<%
String user="11";
request.setAttribute("user",user);
%>
user=${
user}
</body>
结果:user=11
例子3:<body>
<%
pageContext.setAttribute("add","11");
request.setAttribute("add","22");
session.setAttribute("add","33");
application.setAttribute("add","44");
%>
add=${
add}
//查询的顺序依次是pageContext,request,session,application
//查询到以后显示,刷新页面则会查询下一个
</body>
--%>
</body>
</html>
bean属性
EL的Bean属性:第一步:创建一个类
package com;
public class Student{
private String name;
private int age;
public Student(){
super();
}
public Student(){
super();
this.name=name;
this.age=age;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return age;
}
@Override
public String toString(){
return "Student[name="+name+",age="+age+"]";
}
}
第二步,在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>
<%
Student student=new Student("张三",25);
pageContext.setAttribute("student",student);
%>
student=${
student}<!--接受student所有的值-->
name=${
student.name}<!--接受student中name的值-->
</body>
</html>
版权声明
本文为[你若信]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_44152890/article/details/124330838
边栏推荐
- Chapter 15 new technologies of software engineering
- Wechat applet input hidden and inoperable settings
- 关于stream流,浅记一下------
- org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su
- 使用itextpdf实现截取pdf文档第几页到第几页,进行分片
- 使用Postman进行Mock测试
- 微信小程序基于udp协议与esp8266进行通信
- New关键字的学习和总结
- 1到100号的灯开关问题
- 服务器日志分析工具(识别,提取,合并,统计异常信息)
猜你喜欢

Jmeter安装教程以及我遇到的问题的解决办法

Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)

微信小程序的订阅号开发(消息推送)

groutine

linux安装mysql后修改密码

Easyexcel读取excel表地理位置数据,按中文拼音排序

Windos中安装labellmg教程

关于密匙传递的安全性和数字签名

基于CM管理的CDH集群集成Phoenix

org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su
随机推荐
Pycharm连接远程服务器并实现远程调试
JDBC入门
Node接入支付宝开放平台的沙箱实现支付功能
趣谈网络协议
MYSQL 主从同步避坑版教程
_模_板_
收藏博客贴
9月8日,临去松山湖的前夜
CentOS mysql多实例部署
Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
leetcode--977. Squares of a Sorted Array
更改plsql工具栏的图标大小
基于CM管理的CDH集群集成Phoenix
查询2013年到2021年的数据,只查询到2020的数据,遇到了这个问题所进行的解决办法
编程旅行之函数
request模块
服务器日志分析工具(识别,提取,合并,统计异常信息)
帆软中需要设置合计值为0时,一整行都不显示的解决办法
帆软中使用if else 进行判断-使用标题条件进行判断
关于stream流,浅记一下------