servlet

来源:互联网 发布:西安java大数据招聘 编辑:程序博客网 时间:2024/05/18 00:26
一、ServletRequest接口
  定义
  interface ServletRequest
  在javax.servlet包中。
  方法
  1、getAttribute
  public Object getAttribute(String name)
  返回以name为名字的属性的值。如果该属性不存在,这个方法将返回null。
  2、getAttributeNames
  public Enumeration getAttributeNames()
  返回请求中所有可用的属性的名字。如果在请求中没有属性,这个方法将返回一个空的枚举集合。
  3、removeAttribute
  public void removeAttribute(String name)
  移除请求中名字为name的属性。
  4.setAttribute
  public void setAttribute(String name,Object o)
  在请求中保存名字为name的属性。如果第二个参数o为null,那么相当于调用removeAttribute(name)。
  5、getCharacterEncoding
  public String getCharacterEncoding()
  返回请求正文使用的字符编码的名字。如果请求没有指定字符编码,这个方法将返回null。
  6、getContentLength
  public int getContentLength()
  以字节为单位,返回请求正文的长度。如果长度不可知,这个方法将返回-1。
  7、getContentType
  public String getContentType()
  返回请求正文的MIME类型。如果类型不可知,这个方法将返回null。
  8、getInputStream
  public ServletInputStream getInputStream()
  返回一个输入流,使用该输入流以二进制方式读取请求正文的内容。javax.servlet.ServletInputStream是一个抽象类,继承自InputStream。
  9、getLocalAddr
  public String getLocalAddr()
  返回接收到请求的网络接口的IP地址,这个方法是在Servlet 2.4规范中新增的方法。
  10、getLocalPort
  public int getLocalPort()
  返回接收到请求的网络接口的IP端口号,这个方法是在Servlet 2.4规范中新增的方法。
  11、getLocalName
  public String getLocalName()
  返回接收到请求的IP接口的主机名,这个方法是在Servlet 2.4规范中新增的方法。
  12、getParameter
  public String getParameter(String name)
  返回请求中name参数的值。如果name参数有多个值,那么这个方法将返回值列表中的第一个值。如果在请求中没有找到这个参数,这个方法将返回null。
  13、getParameterNames
  public Enumeration getParameterNames()
  返回请求中包含的所有的参数的名字。如果请求中没有参数,这个方法将返回一个空的枚举集合。
  14、getParameterValues
  public String[ ] getParameterValues(String name)
  返回请求中name参数所有的值。如果这个参数在请求中并不存在,这个方法将返回null。
  15、getReader
  public BufferedReader getReader() throws IOException
  返回BufferedReader对象,以字节数据方式读取请求正文。
  16、getRemoteHost
  public java.lang.String getRemoteHost()
  返回发送请求的客户端或最后一个代理服务器的完整限定名。
  17、getRemotePort
  public int getRemotePort()
  返回发送请求的客户端或者最后一个代理服务器的IP源端口, 这个方法是在Servlet 2.4规范中新增的方法。
  18、 getRequestDispatcher
  public RequestDispatcher getRequestDispatcher(String path)
  返回RequestDispatcher对象,作为path所定位的资源的封装。
  19、getServerName
  public String getServerName()
  返回请求发送到的服务器的主机名。
  20、getServerPort
  public int getServerPort()
  返回请求发送到的服务器的端口号。
  21、setCharacterEncoding
  public void setCharacterEncoding(String env)throws UnsupportedEncodingException 
  覆盖在请求正文中所使用的字符编码的名字。