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 ...
随机推荐
- WPF-控件-编辑圆角TextBox
使用模板 代码如下: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xm ...
- python之方法总结
python的OOP的方法有3种: 1. 实例方法: 接收self参数 2. 类方法: 接收cls参数, 并要用classmethod()注册或者@classmethod注解. 3. 静态方法: 不接 ...
- iOS常见问题(1)
一.storyboard连线问题 产生原因:将与storyboard关联的属性删除了,但是storyboard中还保持之前所关联的属性. 解决: 1.点击view controller 2.点击这排最 ...
- 学习Linux第一天
1.简介: 记住这个名字:Linus Torvals 系统组成:Linux内核,Shell, 文件系统,实时程序 Tips:在系统启动过程中,使用Alt+F2组合键,可以查看Ubuntu启动的详细过程 ...
- word小技巧
如何将英文和数字替换为times new romans 1,点击替换(ctrl+H) .2,在查找内容中输入”([A-Z0-9])“(不包括引号,但包括小括号),这是替换所有大写字母和数字,如果还想替 ...
- android编程常见问题-程序真机中不显示
新手编程常见问题: 问题表现:连接上手机后,程序不显示 解决版本:检查AndroidManifest.xml 文件中SDK版本的设置(要求要兼容当前手机版本系统),如下:
- 2124: 等差子序列 - BZOJ
Description 给一个1到N的排列{Ai},询问是否存在1<=p1=3),使得Ap1,Ap2,Ap3,…ApLen是一个等差序列. Input 输入的第一行包含一个整数T,表示组数.下接 ...
- ASP文件操作(FSO)详解
实例一:写入文件 语法 object.CreateTextFile([要建立的文件],[如存在,是否替代]) <% Set fs =Server.CreateObject("Scrip ...
- 140304笔记, mysql 更改自动增长字段值的重新设定
1. 存在同名的或不同的namespace交错情况. Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result m ...
- android C/C++ source files 全局宏定义 .
\system\core\include\arch\linux-arm AndroidConfig.h * ============================================== ...