- 1、本文档共4页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
request对象属性
E-Mail :mldnqa@163.com
request 实际上是服务器端接收客户端请求的信息的
接收信息之后,做进一步处理
getParameter :接收请求参数的
中文该如何处理
1 、对所有的数据进行再编码:ISO8859-1 编码
String 类中的 getBytes(ISO8859-1) ;
getBytes()方法定义:
public byte[] getBytes(encoding)
再将 byte 数组重新变为字符串
之所以会出现问号,根本原因,就是此文字不在正常编码范围之中
GBK GB2312
GBK 是中文编码、GB2312 是简体中文编码
%@ page contentType=text/html;charset=gbk%
html
body
E-Mail :mldnqa@163.com
%
// 接收内容
String name = request.getParameter(uname) ;
byte[] b = name.getBytes(ISO8859-1) ;
name = new String(b) ;
String name = new String(request.getParameter(uname).getBytes(ISO8859-1)) ;
%
h1输入内容为:%=name%/h1
/body
/html
2 、设置统一字符编码:
public void setCharacterEncoding(String env)
throws UnsupportedEncodingException
设置统一的请求编码
在 J2EE 中乱码问题是最大的问题 —— 作到国际通用
%@ page contentType=text/html;charset=gbk%
html
body
%
// 接收内容
/*
String name = request.getParameter(uname) ;
byte[] b = name.getBytes(ISO8859-1) ;
name = new String(b) ;
*/
// String name = new String(request.getParameter(uname).getBytes(ISO8859-1)) ;
request.setCharacterEncoding(GBK) ;
String name = request.getParameter(uname) ;
%
h1输入内容为:%=name%/h1
/body
/html
如果传递的内容是数组(复选框的情况下、多个下拉列表项)
使用 request 的以下方法取得数据:
public String[] getParameterValues(String name)
E-Mail :mldnqa@163.com
在开发中较为常用的表单控件:隐藏域
将内容隐藏起来,使用户不能修改,之后随表单一起提交到服务器上显示
html
body
form action=demo06.jsp method=post
input type=hidden name=uname value=mldn
input type=submit value=提交
/form
/body
/html
地址重写
http://localhost/test/basic/04/demo06.jsp?uname=Hello
通过地址重写,可以将内容传递到服务器端 —— 服务器端只认 HTTP 协议,而不管接收的内容是
以何种形式传送过来的
如果传递多个参数呢?
demo06.jsp?uname=MLDNupass=LXH
☆ ge
文档评论(0)