JAVA Web request对象

 request对象 

request对象用于处理HTTP中请求的各项参数,最常用的就是获取请求参数。如果要同时指定多个参数,各参数间使用与(&)符合分隔即可

例通过request对象的getParameter()方法获取传递的参数值代码如下

//index页面用于连接到delta

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>使用request对象获取请求参数值</title>
</head>
<body>
<a href="deal.jsp?id=1&user=">处理页</a>

<--此处的为id指定参数名和值,为user指定字参数名没有指定参数值-->
</body>
</html>

注意:request的getParameter方法获取传递的参数时,如果指定的参数不存在,将返回null,指定了参数名但未指定参数,将返回空的字符串""

//delete页面

<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="utf-8"%>
<%


String id=request.getParameter("id"); //获取id参数的值
String user=request.getParameter("user");//获取user参数的值
String pwd=request.getParameter("pwd");//获取pwd参数值
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>处理页</title>
</head>
<body>
id参数的值为:<%=id %><br>
user参数的值为:<%=user %><br>
pwd参数的值为:<%=pwd %>
</body>
</html>

posted @ 2015-09-15 00:24  星晨-XC  阅读(276)  评论(0编辑  收藏  举报