javaweb:从包含页面中访问变量案例
2023-05-03 12:51:55
哔哩哔哩
来源:我的学习笔记
代码:
(资料图)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>main page</title>
</head>
<body>
<img src="img/tom01.jpg" >
<br>
My name is ???.What is yours?
<form action="" method="post">
<input type="text" name="username" size="30">
<br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
<%@ include file="response.jsp" %>
</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>
<%! String userName="rock"; %>
<% userName=request.getParameter("username");%>
<h1>hello,<%=userName %></h1>
</body>
</html>