JSP内置对象之--request对象

一、乱码解决

void setCharacterEncoding(java.lang.String env)
                          throws java.io.UnsupportedEncodingException

二、接收参数

表单定义,传递各种参数:request_demo_01.html
<html>
<head>
	<title>表单定义,传递各种参数</title>
</head>
<body>
	<form action = "request_demo_01.jsp" method = "post">
		姓名:<input type = "text" name = "uname"><br>
		兴趣:	<input type = "checkbox" name = "inst" value = "跳舞">跳舞		
				<input type = "checkbox" name = "inst" value = "唱歌">唱歌
				<input type = "checkbox" name = "inst" value = "编程">编程
				<input type = "checkbox" name = "inst" value = "游泳">游泳
				<input type = "checkbox" name = "inst" value = "旅游">旅游
				<input type = "hidden" name = "id" value = "3"> 
				<br><input	type ="submit" value = "提交">
				<input type = "reset" value = "重置">
	</form>
</body>
</html>
接收参数:request_demo_01.jsp
<%@ page contentType = "text/html" pageEncoding = "GBK"%>
<html>
<head>
	<title>接收参数</title>
<head>

<body>
	<%
		request.setCharacterEncoding("GBK");
		String name = request.getParameter("uname");
		String id = request.getParameter("id");
		String inst[] = request.getParameterValues("inst");
	%>
		<h3>编号:<%=id%></h3>
		<h3>姓名:<%=name%></h3>
	
<h3>兴趣:
<%
	if(inst!=null){	
%>
	<%
		for (int i = 0; i < inst.length; i++){
	%>
			<%=inst[i]%>、
	<%
		}
	%>
</h3>
	<%
	}	
	%>
</body>
</html>





注意问题:

1、接收内容操作第1步:中文乱码问题

2、重置按钮(reset) VS 按钮 (button)
VS 提交(submit)


3、java.lang.String[] getParameterValues(java.lang.String name)
注意判断空数组,否则会出现:NullPointerException异常



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值