<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>访问总量</title>
</head>
<body>
<%
Integer count = (Integer)application.getAttribute("visitCount");//强制转换 Integer是int的包装类
//Integer可以为null
if(count==null){//没有放数据
application.setAttribute("visitCount",1);
}else{
//取出来数甲一,再放回去
count++;
application.setAttribute("visitCount",count);
}
%>
当前网站访问量:<%=count %>
</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>
<form action="B.jsp" method="post">
<input type="text" value="value in A" name="mytext"/>
<button type="submit">提交</button>
</form>
</body>
</html>```
```c
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
System.out.println("进入B页面");
String value = request.getParameter("mytext");
System.out.print("B页面中获取到A文本框里的值:"+value);
request.setAttribute("mytext","在B页面里往request里加的数据");
System.out.println("往request里添加mytext");
request.getRequestDispatcher("C.jsp").forward(request,response);
System.out.println("B页面处理结束");
%>
<%@ 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>
<%
System.out.println("进入C页面");
String myTextA = request.getParameter("mytext");
System.out.println("获取A页面文本框的值:"+myTextA);
String myTextB =(String) request.getAttribute("mytext");
System.out.println("获取B页面加入的数据:"+myTextA);
System.out.println("C页面处理完毕");
%>
<%
%>
</body>
</html>
A把请求给B
A里面文本框的值提交到B
B页面处理
获取到A页面的值
并且往request里面添加数据
转发到C页面
取到到 属性里面的数据