Servlet--ServletInputStream类,ServletOutputStream类
2015-06-15 11:22
771 查看
ServletInputStream类
定义
public abstract class ServletInputStream extends InputStream
这个类定义了一个用来读取客户端的请求信息的输入流。这是一个 Servlet 引擎提供的抽象类。一个 Servlet 通过使用ServletRequest 接口获得了对一个 ServletInputStream 对象的说明。这个类的子类必须提供一个从 InputStream 接口读取有关信息的方法。
方法
1、readLine
public int readLine(byte[] b, int off, int len) throws IOException;
从输入流的指定的偏移量开始将指定长度的字节读入到指定的数组中。 如果该行所有请求的内容都已被读取,这个读取的过程将结束。如果是遇到了新的一行,新的一行的首个字符也将被读入到数组中。
ServletOutputStream类
定义
public abstract class ServletOutputStream extends OutputStream
这是一个由 Servlet 引擎使用的抽象类。Servlet 通过使用 ServletResponse 接口的使用获得了对一个这种类型的对象的说明。利用这个输出流可以将数据返回到客户端。这个类的子类必须提供一个向 OutputStream 接口写入有关信息的方法。在这个接口中, 当一个刷新或关闭的方法被调用时。 所有数据缓冲区的信息将会被发送到客户端,也就是说响应被提交了。请注意,关闭这种类型的对象时不一定要关闭隐含的socket
流。
方法
1、print
public void print(String s) throws IOException;
public void print(boolean b) throws IOException;
public void print(char c) throws IOException;
public void print(int i) throws IOException;
public void print(long l) throws IOException;
public void print(float f) throws IOException;
public void print(double d) throws IOException;
输出变量到输出流中
2、println
public void println() throws IOException;
public void println(String s) throws IOException;
public void println(boolean b) throws IOException;
public void println(char c) throws IOException;
public void println(int i) throws IOException;
public void println(long l) throws IOException;
public void println(float f) throws IOException;
public void println(double d) throws IOException;
输出变量到输出流中,并增加一个回车换行符。
定义
public abstract class ServletInputStream extends InputStream
这个类定义了一个用来读取客户端的请求信息的输入流。这是一个 Servlet 引擎提供的抽象类。一个 Servlet 通过使用ServletRequest 接口获得了对一个 ServletInputStream 对象的说明。这个类的子类必须提供一个从 InputStream 接口读取有关信息的方法。
方法
1、readLine
public int readLine(byte[] b, int off, int len) throws IOException;
从输入流的指定的偏移量开始将指定长度的字节读入到指定的数组中。 如果该行所有请求的内容都已被读取,这个读取的过程将结束。如果是遇到了新的一行,新的一行的首个字符也将被读入到数组中。
package javax.servlet; import java.io.IOException; import java.io.InputStream; public abstract class ServletInputStream extends InputStream { public int readLine(byte[] b, int off, int len) throws IOException { if (len <= 0) { return 0; } int count = 0; int c; while ((c = read()) != -1) { b[(off++)] = (byte)c; count++; if (c == 10) break; if (count == len) { break; } } return count > 0 ? count : -1; } }
ServletOutputStream类
定义
public abstract class ServletOutputStream extends OutputStream
这是一个由 Servlet 引擎使用的抽象类。Servlet 通过使用 ServletResponse 接口的使用获得了对一个这种类型的对象的说明。利用这个输出流可以将数据返回到客户端。这个类的子类必须提供一个向 OutputStream 接口写入有关信息的方法。在这个接口中, 当一个刷新或关闭的方法被调用时。 所有数据缓冲区的信息将会被发送到客户端,也就是说响应被提交了。请注意,关闭这种类型的对象时不一定要关闭隐含的socket
流。
方法
1、print
public void print(String s) throws IOException;
public void print(boolean b) throws IOException;
public void print(char c) throws IOException;
public void print(int i) throws IOException;
public void print(long l) throws IOException;
public void print(float f) throws IOException;
public void print(double d) throws IOException;
输出变量到输出流中
2、println
public void println() throws IOException;
public void println(String s) throws IOException;
public void println(boolean b) throws IOException;
public void println(char c) throws IOException;
public void println(int i) throws IOException;
public void println(long l) throws IOException;
public void println(float f) throws IOException;
public void println(double d) throws IOException;
输出变量到输出流中,并增加一个回车换行符。
package javax.servlet; import java.io.CharConversionException; import java.io.IOException; import java.io.OutputStream; import java.text.MessageFormat; import java.util.ResourceBundle; public abstract class ServletOutputStream extends OutputStream { private static final String LSTRING_FILE = "javax.servlet.LocalStrings"; private static ResourceBundle lStrings = ResourceBundle.getBundle("javax.servlet.LocalStrings"); public void print(String s) throws IOException { if (s == null) s = "null"; int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if ((c & 0xFF00) != 0) { String errMsg = lStrings.getString("err.not_iso8859_1"); Object[] errArgs = new Object[1]; errArgs[0] = new Character(c); errMsg = MessageFormat.format(errMsg, errArgs); throw new CharConversionException(errMsg); } write(c); } } public void print(long l) throws IOException { print(String.valueOf(l)); } //println无参方法 public void println() throws IOException { print("\r\n"); } //print()之后 在调下println无参方法 public void println(String s) throws IOException { print(s); println(); } public void println(int i) throws IOException { print(i); println(); } }
相关文章推荐
- Servlet--ServletInputStream类,ServletOutputStream类
- PHP加密解密字符串汇总_php技巧_脚本之家
- php 原生的文件上传
- 概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM
- Zend Studio 10正式版破解及汉化
- ubuntuserver10.04 安装LAMP:PHP及配置drupal
- ubuntu server 10.04 安装PHP强化模块
- yii php.ini 时区设置
- 学习php常用算法
- 解决xftp远程连接后出现中文乱码
- php中静态全局变量和全局变量的简单理解
- 安装PHP后,启动YII项目报错
- php中引用&的真正理解-变量引用、函数引用、对象引用
- php 怎样读取指定目录下面的所有文件?
- php curl如何使用以及如何使用代理服务器
- 使用PHP制作 简易员工管理系统之八(使用COOKIE保存用户登陆id以及显示用户登录时间)
- 错误之thinkphp模型使用发生的错误
- PHP中new static()与new self()的区别
- php实现求相对时间函数
- PHP检测用户语言的方法