jsp学习笔记--内置对象--request对象

jsp学习笔记–内置对象–request对象

HTTP通信协议是用户与服务器之间一种提交(请求)信息与相应信息(request/response)的通信协议。request是实现了ServletRequest接口类的一个实例。

  1. 获取用户提交的信息
    request对象获取用户提交信息的最常用的方法getParameter(String s).
    实例:在test01.jsp页面输入三个数字,提交到test02.jsp,并计算出和。
    test01.jsp
<% @ page conteneType="text/html;charset=gb2312" %>
<html><body bgcolor=cyan>
<form action="test01.jsp" moethod="post">
<input type="text" name="a" value=1 size=6>
<input type="text" name="b" value=1 size=6>
<input type="text" name="c" value=1 size=6>
</form>

test02.jsp

<% @ page conteneType="text/html;charset=gb2312" %>
<html><bod<% @ page conteneType="text/html;charset=gb2312" %>
<html><body bgcolor=yellow>
<% String A=request.getParameter("a");
   String B=request.getParameter("b");
   String C=request.getParameter("c");
   try{
       double x=Double.parseDouble(A);
       double y=Double.parseDouble(B);
       double z=Double.parseDouble(C);
       double sum=x+y+z;
       out.println("三个数的和是:"+sum):
   }
   catch(NumberFormatException ee){
       out.println("请输入数字字符!");
   }
   %>
   </body></html>
  1. 处理汉字信息
    a.对信息重新编码。
    request将获取的信息重新编码,并将编码存放到一个字节数组中。
 String str=request.getParameter("message");
     byte b[]=str.get.Parameter("gb2312");
     str=new String(b);   //此时的表单内容必须是在动态页面中。jsp页面。

b.request设置编码
request在获取信息之前使用setCharacterEncoding方法设置自己的编码。

request.setCharacterEncoding("gb2312");
//此时表单为静态页面,html页面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值