HttpServletRequest接口实例化的使用
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接口实例化的使用的更多相关文章
- HttpServletRequest 接口、HttpServletResponse 接口、请求转发与重定向
上篇文章我们讲了servlet的基本原理,这章将讲一下剩余的部分. HttpServletRequest 接口 该接口是 ServletRequest 接口的子接口,封装了 HTTP 请求的相关信息, ...
- Servlet(6)—HttpServletRequest接口和HttpServletResponse接口
HttpServletRequest接口和HttpServletResponse接口是继承ServletRequest和ServletResponse接口,是他们的子接口,但是我们在程序中进程看到Se ...
- 一、HttpServletRequest接口 二、HttpServletReponse接口 三、POST和GET请求方式及其乱码处理 四、ServletContext对象和ServletConfig对象
一.HttpServletRequest接口 内部封装了客户端请求的数据信息 接收客户端的请求参数.HTTP请求数据包中配置参数 ###<1>常用方法 getContextPath()重要 ...
- HttpServletRequest接口
package com.hongdian; import java.util.Enumeration; import java.io.IOException; import javax.servlet ...
- javax.servlet.http.httpServletRequest接口
HttpServletRequest接口中常用的方法: - String getContentPath();//获取webapp根目录路径,如下图: 下面研究request到底是一个怎样的范围 ...
- HttpServletRequest接口是怎么实现的
request只是规范中的一个名称而已.不是SUN提供的,这是由各个不同的Servlet提供商编写的,SUN只是规定这个类要实现HttpServletRequest接口,并且规定了各个方法的用途,但具 ...
- HttpServletRequest接口详解
般情况下,浏览器(客户端)通过 HTTP 协议来访问服务器的资源,Servlet 主要用来处理 HTTP 请求.Servlet 处理 HTTP 请求的流程如下: Servlet 容器接收到来自客户端的 ...
- thinkphp 调用wsdl接口实例化SoapClient抛出异常
异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load externa ...
- PHP调用wsdl接口实例化SoapClient抛出异常
异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load externa ...
随机推荐
- SQL随机数的生成
下面是一个随机函数问题,获取两位数的随机数,且不重复. 但是说明一下,这个函数有点bug,例如:两位数的函数最后能生成89个,如果将数量改成90,那么就无法生成,陷入死循环了. IF object_i ...
- [MySql] 设置了UTF8,中文存数据库中仍然出现问号
运行命令:SHOW VARIABLES LIKE 'character_set_%'; 结果 'character_set_client', 'utf8' 'character_set_connect ...
- Ubuntu 常用软件安装方法
macubuntu 安裝方法: $wget https://github.com/downloads/ChinaLuo/Mac_Ubuntu/Mac_Ubuntu-12.04.tar.gz -O /t ...
- [转载+原创]Emgu CV on C# (七) —— Emgu CV on 轮廓检测
轮廓检测 对于查找轮廓我们一般要对图像Canny检测.但是对于很特殊的场合其实我们还可以直接对二值化的图像进行轮廓的提取. 关键函数 1. cvFindContours Retrieves conto ...
- Python标准库之os模块
1.删除和重命名文件 import os import string def replace(file, search_for, replace_with): # replace strings in ...
- Windows Phone 8.1 与 Windows Phone 8.1 Silverlight区别
以下讨论基于当前的WP8 APP, 一.Windows Phone 8 app:旧的WP8程序:不需要迁移: 二.Windows Phone 8.1 app新的使用Windows Runtime 的程 ...
- STS中取消show in Breadcrumb方法
前言:STS是Spring产品下的一个开发工具,它和eclipse很像,只不过对Spring有更好的兼容.Show in Breadcrumb是快速导航条,可以清晰的看到我们当前的类,属性或方法的导航 ...
- 【贪心】Bzoj 2457:[BeiJing2011]双端队列
2457: [BeiJing2011]双端队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 209 Solved: 95[Submit][Stat ...
- hdu 4888
网络流建模,建模不难,难在找环: #include<cstdio> #include<algorithm> #include<vector> #include< ...
- 词法分析器flex的使用
词法分析器flex的功能说起来就是一句话,将正则表达式转化为c代码. flex编译成功后会生成一个flex.exe的可执行文件.此时,我们需要一个定义了正则表达式 动作的input文件.例如test. ...