当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
腾讯根据ip解析地址
全局变量能否放在头文件中定义
poi操作word模板替换数据并且导出word
帆软中使用if else 进行判断-使用标题条件进行判断
Node接入支付宝开放平台的沙箱实现支付功能
SPC简介
微信小程序通过低功耗蓝牙设备进行定位及测距(二)
理解虚基类、虚函数与纯虚函数的概念(转)
Wechat applet positioning and ranging through low-power Bluetooth device (2)
程序编译调试学习记录
There is a mining virus in the server
CentOS mysql多实例部署
Chapter I review of e-commerce spike products
Un modèle universel pour la construction d'un modèle d'apprentissage scikit
快速安装mongodb
基于CM管理的CDH6.3.2集群集成Atlas2.1.0
As a junior college student, I studied hard in closed doors for 56 days, won Ali offer with tears, five rounds of interviews and six hours of soul torture
JDBC入门
Nacos+AspnetCore+Ocelot实战编码
Prediction of tomorrow's trading limit of Low Frequency Quantization