当前位置: 首页 > news >正文

jsp指令和动作

1.page指令:描述页面信息

pageENcoding:软件编码

contentType:浏览器编码

2.include指令:将多个网页合成一个网页,静态包含网页

问题:1.在网页源代码中,会形成错误的多遍代码,将主页面代码和副页面各删除一半。

           2.多个网页中的代码不能有任何冲突

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ include file ="NewFile.jsp" %><h3>这位是一个主网页1</h3>
<h3>这是另一个网页的变量:<%=a %></h3>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>这是一个导航栏</h3>
<h3><% int a=12;%></h3>

 

查看网页源代码

 

完整代码

 

3.include动作

jsp动作:include,param,forward

基本语法:

1.<jsp:include page=""/>

2.<jsp:include page="">

包含网页传递数据

include指令:静态包含,代码复用,一起生成网页,

注意:被包含网页不需要写部分网页代码,一起编译执行,运行1次,运行效率高

include动作:动态包含,结果复用,共同生成网页,

注意:被包含网页不需要写结构网页代码,一起编译执行,运行多次,运行效率低

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="NewFile1.jsp"/>
<h3>这是一个网页1</h3>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html><h3>次级网页</h3>

4.param动作

param动作:向其他网页传递数据

用法:<jsp:param value="值" name="值对应的名字">

注意事项:动作不能单独使用,要和其他动作一起使用

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="NewFile1.jsp">
<jsp:param value="18" name="age"/>
</jsp:include>
<h3>这是一个网页1</h3>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html><h3>次级网页</h3>
<%String s = request.getParameter("age");out.print(s);%>

传递中文乱码:数据传输和数据接收编码

解决方法:在发送和接收的网页中添加<%request.setCharacterEncoding("UTF-8");%>

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><%request.setCharacterEncoding("UTF-8");%>
<jsp:include page="NewFile1.jsp">
<jsp:param value="12" name="id1"/>
<jsp:param value="12.34" name="id2"/>
<jsp:param value="张红" name="id3"/>
</jsp:include>
<h3>这是一个网页1</h3>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html><h3>次级网页</h3>
<%request.setCharacterEncoding("UTF-8");String s = request.getParameter("id1");String s1 = request.getParameter("id2");String s2 = request.getParameter("id3");Double b = Double.parseDouble(s1)+10;//把s字符串转换为double类型Integer i=Integer.parseInt(s)+10;//首字母大写是类名String s5=b + "";out.print(s);out.print(s1);out.print(s2);
%>

forward:跳转到新页面

跳转到新页面

语法:1.<jsp:forward page=“relativeURL”>不用传参数

2.<jsp:forward page="要转向的页面" >

使用param动作传递数据

<jsp:param name= "paramterName" value= " parametrValue" />传参数

</jsp:forward>

注意:用forward跳转后的页面显示的网址是跳转之前的网页

执行forward代码后不在执行

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><h3>这是主页面</h3><%-- <jsp:forward page="NewFile1.jsp"/>  --%><%request.setCharacterEncoding("UTF-8");%><jsp:forward page="NewFile1.jsp" ><jsp:param name= "张三"  value= "name" /></jsp:forward> <% request.setAttribute("id", "18");   %></body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><%request.setCharacterEncoding("UTF-8"); %> <h3>这是跳转网页</h3><%String s = request.getParameter("name");%><%out.print(request.getAttribute("id"));%><h3>登录成功,欢迎</h3>
</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><h3>这是主页面</h3><%-- <jsp:forward page="NewFile1.jsp"/>  --%><%request.setCharacterEncoding("UTF-8");%><% request.setAttribute("id", "18");   %><jsp:forward page="NewFile1.jsp" ><jsp:param name= "张三"  value= "name" /></jsp:forward> </body>
</html>

 

相关文章:

  • Unity PS5开发 天坑篇 之 URP管线与HDRP管线部署流程以及出包介绍04
  • 快速幂算法在Java中的应用
  • vue页面实现左右div宽度,上下div高度分割线手动拖动高度或者宽度自动变化,两个div宽度或者高度拉伸调节,实现左右可拖动改变宽度的div内容显示区
  • 通过Caliper进行压力测试程序,且汇总压力测试问题解决
  • 20款Python办公自动化库精选,一键提升效率!
  • itextPdf生成pdf简单示例
  • 前后端实时数据通信
  • ESP32
  • python爬虫----python列表高级
  • 【踩坑】使用CenterNet训练自己的数据时的环境配置与踩坑
  • 项目四-图书管理系统
  • AcWing 173.矩阵距离
  • Excel·VBA数组平均分组问题
  • Kubernetes 知识体系 系列一
  • Python最强自动化神器!
  • [LeetCode] Wiggle Sort
  • [分享]iOS开发-关于在xcode中引用文件夹右边出现问号的解决办法
  • 【剑指offer】让抽象问题具体化
  • 【跃迁之路】【699天】程序员高效学习方法论探索系列(实验阶段456-2019.1.19)...
  • HTML中设置input等文本框为不可操作
  • Laravel 实践之路: 数据库迁移与数据填充
  • Median of Two Sorted Arrays
  • node和express搭建代理服务器(源码)
  • SpiderData 2019年2月23日 DApp数据排行榜
  • SpringCloud(第 039 篇)链接Mysql数据库,通过JpaRepository编写数据库访问
  • 第十八天-企业应用架构模式-基本模式
  • 检测对象或数组
  • 两列自适应布局方案整理
  • 小程序01:wepy框架整合iview webapp UI
  • 一天一个设计模式之JS实现——适配器模式
  • media数据库操作,可以进行增删改查,实现回收站,隐私照片功能 SharedPreferences存储地址:
  • 7行Python代码的人脸识别
  • 说说我为什么看好Spring Cloud Alibaba
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • (12)Hive调优——count distinct去重优化
  • (3)nginx 配置(nginx.conf)
  • (Redis使用系列) SpringBoot中Redis的RedisConfig 二
  • (第9篇)大数据的的超级应用——数据挖掘-推荐系统
  • (欧拉)openEuler系统添加网卡文件配置流程、(欧拉)openEuler系统手动配置ipv6地址流程、(欧拉)openEuler系统网络管理说明
  • (译) 函数式 JS #1:简介
  • (转)ABI是什么
  • (转)C#调用WebService 基础
  • (转)MVC3 类型“System.Web.Mvc.ModelClientValidationRule”同时存在
  • **PyTorch月学习计划 - 第一周;第6-7天: 自动梯度(Autograd)**
  • *ST京蓝入股力合节能 着力绿色智慧城市服务
  • ./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’: ./incl
  • .NET 4.0中使用内存映射文件实现进程通讯
  • .Net 访问电子邮箱-LumiSoft.Net,好用
  • .net6使用Sejil可视化日志
  • .NET程序员迈向卓越的必由之路
  • .net实现头像缩放截取功能 -----转载自accp教程网
  • @EnableAsync和@Async开始异步任务支持
  • @hook扩展分析
  • @RequestMapping 的作用是什么?