javaweb:從包含頁面中訪問變量案例
來源:我的學習筆記


代碼:
<%@ 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>