訪問請求參數request.getParameter()
制作人:全心全意
getParameter()
例:
傳遞參數頁:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.util.Date"%> <%@ page import="java.text.SimpleDateFormat" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>request對象-->訪問請求參數1</title> </head> <body> <a href="index1.jsp?id=1&user=">處理頁</a> </body> </html>
獲取參數頁:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String id = request.getParameter("id");
String user = request.getParameter("user");
String pwd = request.getParameter("pwd");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>request對象-->訪問請求參數2</title>
</head>
<body>
<%-- index.jsp頁面中傳遞了id參數,並且進行了賦值,id值為1 --%>
id參數的值為:<%=id %><br/>
<%-- index.jsp頁面中傳遞了user參數,卻沒有賦值,user值為“空白” --%>
user參數的值為:<%=user %><br/>
<%-- index.jsp頁面中沒有傳遞pwd參數,pwd值為null --%>
pwd參數的值為:<%=pwd %><br>
</body>
</html>
