JavaWeb使用request对象获取请求参数值

来源:互联网 发布:手机蓝牙软件下载 编辑:程序博客网 时间:2024/05/22 04:36



<!---- index.jsp ---->

<%@ page language="java" contentType="text/html; charset=GB18030"

    pageEncoding="GB18030"%>
<!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=GB18030">
<title>页面请求对象request</title>
</head>
<body>
<a href = "show.jsp?id= 001">点击获取请求参数的值</a> <!-- 等号“=”的左侧不能有空格,否则按null处理 -->
<br />
<!-- 
1.在通过" ? "来指定请求参数时,参数值不需要使用单引号或双引号括起来,包括字符型的参数。
2.在通过问号“?” 来指定请求参数时,可以同时指定多个参数,各参数间使用与符号“ & ”分隔即可。
-->
<a href = "delet.jsp ? id = 002">删除文件</a>
 
<!-- 
说明:在使用request对象的getParameter()方法获取传递的参数值时,如果指定的参数不存在,将返回零如果指定了参数名,但未指定参数值,将返回空的字符串。
 -->
</body>

</html>

--------------------------------------------------------------------------------------------------------------------------------------------------------

<!--  show.jsp -->

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
ID参数的值为:<%= request.getParameter("id") %><br>
name参数的值为:<%= request.getParameter("name") %>
</body>
</html>

0 0