HttpServletRequ接口的使用和jsp内置对象的request对象非常类似,request对象其实

就是HttpServletRequest接口的一个实例,不过气实例化的过程是自动的,无须自定义。

以下示例达到的效果为:通过一个HttpServletRequest接口的实利化对象设置并取得

request范围属性的示例。

RequestDemo.java

 package com.mhb;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class RequestDemo extends HttpServlet { public void init() throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { //设置输出内容的格式和编码
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter(); 22 //存储在request范围内
23 request.setAttribute("name", "测试者");
24 //取得request范围name的属性
25 String name = (String) request.getAttribute("name"); out.println("<html>");
out.println("<body>");
29 out.println("name:"+name);
out.println("</body>");
out.println("</html>"); }
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
public void destroy() {
super.destroy();
}
}

浏览器显示:

HttpServletRequest接口实例化的使用的更多相关文章

  1. HttpServletRequest 接口、HttpServletResponse 接口、请求转发与重定向

    上篇文章我们讲了servlet的基本原理,这章将讲一下剩余的部分. HttpServletRequest 接口 该接口是 ServletRequest 接口的子接口,封装了 HTTP 请求的相关信息, ...

  2. Servlet(6)—HttpServletRequest接口和HttpServletResponse接口

    HttpServletRequest接口和HttpServletResponse接口是继承ServletRequest和ServletResponse接口,是他们的子接口,但是我们在程序中进程看到Se ...

  3. 一、HttpServletRequest接口 二、HttpServletReponse接口 三、POST和GET请求方式及其乱码处理 四、ServletContext对象和ServletConfig对象

    一.HttpServletRequest接口 内部封装了客户端请求的数据信息 接收客户端的请求参数.HTTP请求数据包中配置参数 ###<1>常用方法 getContextPath()重要 ...

  4. HttpServletRequest接口

    package com.hongdian; import java.util.Enumeration; import java.io.IOException; import javax.servlet ...

  5. javax.servlet.http.httpServletRequest接口

    HttpServletRequest接口中常用的方法:   - String getContentPath();//获取webapp根目录路径,如下图:   下面研究request到底是一个怎样的范围 ...

  6. HttpServletRequest接口是怎么实现的

    request只是规范中的一个名称而已.不是SUN提供的,这是由各个不同的Servlet提供商编写的,SUN只是规定这个类要实现HttpServletRequest接口,并且规定了各个方法的用途,但具 ...

  7. HttpServletRequest接口详解

    般情况下,浏览器(客户端)通过 HTTP 协议来访问服务器的资源,Servlet 主要用来处理 HTTP 请求.Servlet 处理 HTTP 请求的流程如下: Servlet 容器接收到来自客户端的 ...

  8. thinkphp 调用wsdl接口实例化SoapClient抛出异常

    异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load externa ...

  9. PHP调用wsdl接口实例化SoapClient抛出异常

    异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load externa ...

随机推荐

  1. MySQL实战积累

    IFNULL(expr1,expr2)的用法:假如expr1不为NULL,则IFNULL()的返回值为   expr1; 否则其返回值为expr2. 索引:http://www.cnblogs.com ...

  2. 用Python作GIS之四:Tkinter基本界面的搭建

    Python下的主窗口可以定义如下:def start(self):        #self.project = Project("temp")        #self.pro ...

  3. python之字串

    python字串声明: 单引('), 双引("), 三引(''' 或 """"). python字串前缀: r表示原生字串, 字串内容: (1)不能包 ...

  4. mootools和jquery冲突的解决

    mootools-jquery 今天在做EcStore前台的做效果时,由于Jquery的插件比较多,于是就使用了Jquery的插件,但是发现会引起Mootools的冲突. 于是猛找资料,终于找到了,现 ...

  5. Animations--动画基础

    基础动画 //1.在0.5s内,将_field.alpha 的数值变为1.0 [UIView animateWithDuration:0.5 animations:^{ _field.alpha = ...

  6. [搜片神器]winform程序自己如何更新自己的方法代码

    DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr 国外测试 ...

  7. CSS进阶

    盒子模型的边框就是围绕着内容及补白的线,这条线你可以设置它的粗细.样式和颜色(边框三个属性). 1.border-style(边框样式)常见样式有:dashed(虚线)| dotted(点线)| so ...

  8. Python求算数平方根和约数

    一.求算术平方根 a=0 x=int(raw_input('Enter a number:')) if x >= 0: while a*a < x: a = a + 1 if a*a != ...

  9. STS中取消show in Breadcrumb方法

    前言:STS是Spring产品下的一个开发工具,它和eclipse很像,只不过对Spring有更好的兼容.Show in Breadcrumb是快速导航条,可以清晰的看到我们当前的类,属性或方法的导航 ...

  10. [转载]App.Config详解及读写操作

    App.Config详解 应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的.它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而不必重编译应用程序.配置文件的根节点是c ...