当前位置:网站首页>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
边栏推荐
猜你喜欢
帆软实现分页时第一行和最后两行冻结方式
Pytorch 经典卷积神经网络 LeNet
Pycharm连接远程服务器并实现远程调试
STM32学习记录0007——新建工程(基于寄存器版)
RobotFramework 之 用例标签机制
Autumn recruitment in 2021, salary ranking No
Basic knowledge learning record
Prediction of tomorrow's trading limit of Low Frequency Quantization
Lin Lin, product manager of Lenovo: network failure of local network operator in Tianjin. The background server of Zui system can't work normally for the time being
使用Postman进行Mock测试
随机推荐
mysql新表,自增id长达20位,原因竟是......
findstr不是内部或外部命令解决方法
Neuron and neural network
Promtail + Loki + Grafana 日志监控系统搭建
Basic knowledge learning record
PySide2
烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
Nifi 快速安装及文件同步操作
RobotFramework 之 用例标签机制
生产环境——
帆软分割求解:一段字符串,只取其中某个字符(所需要的字段)
_模_板_
Nacos+AspnetCore+Ocelot实战编码
RobotFramework 之 文件上传和下载
POI operation word template replaces data and exports word
微信小程序setInterval定时函数使用详细教程
初识go语言
Interesting talk about network protocol
STM32学习记录0007——新建工程(基于寄存器版)
SPC简介