访问请求参数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>