| 风信Java论坛 ›› J2EE/Java Web 讨论交流中心 ›› JSP内建对象 | 登录 -> 注册 |
|
1F JSP内建对象 jastby Post by : 2008-05-30 16:51:45.0
① out - javax.servlet.jsp.jspWriter 方法: 2. void clearBuffer() ; 3. void close() ; 4. void flush() ; 5. int getBufferSize() ; 6. int getRemaining() ; 7. boolean isAutoFlush() ; 8. void newLine() ; 9. void print( boolean b ) ; 10. void println( boolean b ) ; 成员:
方法: 2. Enumeration getAttributeNames() ; 3. String getAuthType() ; 4. String getCharacterEncoding() ; 5. int getContentLength() ; 6. String getContentType() ; 7. String getContentPath() ; 8. Cookie[] getCookies() ; 9. Enumeration getHeaderNames() ; 10. Enumeration getHeaders( String name ) ; 11. String getHeader( String name ) ; 12. long getDateHeader( String name ) ; 13. int getIntHeader( String name ) ; 14. ServletInputStream getInputStream() ; 15. Locale getLocale() ; 16. Enumeration getLocales() ; 17. String getLocalName() ; 18. String getLocalAddr() ; 19. int getLocalPort() ; 20. String getMethod() ; 21. String getParameter( String name ) ; 22. Map getParameterMap() ; 23. Enumeration getParameterNames() ; 24. String[] getParameterValues( String name ) ; 25. String getQueryString() ; 26. String getPathInfo() ; 27. String getPathTranslated() ; 28. String getProtocol() ; 29. BufferedReader getReader() ; 30. String getRemoteAddr() ; 31. String getRemoteHost() ; 32. String getRemoteUser() ; 33. int getRemotePort() ; 34. String getRealPath( String path ) ; 35. RequestDispatcher getRequestDispatcher( String path ) ; 36. String getRequestedSessionId() ; 37. String RequestURI() ; 38. StringBuffer getRequestURI() ; 39. String getScheme() ; 40. String getServerName() ; 41. String getServletPath() ; 42. int getServerPort() ; 43. void removeAttribute( String name ) ; 44. void setAttribute( String name, Object value ) ; 45. void setCharacterEncoding( String name ) ; 46. HttpSession getSession() ; 48. boolean isRequestedSessionIdFromURL() ; 49. boolean isRequestedSessionIdValid() ; 50. boolean isSecure() ; 51. boolean isUserInRole( String role ) ; 52. Principal getUserPrincipal() ; 成员:
方法: 2. void addDateHeader( String name, long value ) ; 3. void addHeader( String name, String value ) ; 4. void addIntHeader( String name, int value ) ; 5. boolean containsHeader( String name ) ; 6. String encodeRedirectURL( String url ) ; 7. String encodeURL( String url ) ; 9. int getBufferSize() ; 10. String getCharacterEncoding() ; 11. String getContentType() ; 12. Locale getLocale() ; 13. ServletOutputStream getOutputStream() ; 14. PrintWriter getWriter() ; 15. boolean isCommitted() ; 16. void reset() ; 17. void resetBuffer() ; 18. void sendError( int xc, String msg ) ; 19. void sendRedirect( String locationg ) ; 20. void setBufferSize( int size ) ; 21. void setCharacterEncoding( String charset ) ; 22. void setContentLength( int length ) ; 23. void setContentType( String type ) ; 24. void setDateHeader( String name, long value ) ; 25. void setHeader( String name, String value ) ; 26. void setIntHeader( String name, int value ) ; 27. void setStatus( int xc ) ; 成员(HTTP状态码):
方法: 2. Enumeration getAttributeNames() ; 3. long getCreationTime() ; 4. String getId() ; 5. long getLastAccessedTime() ; 6. int getMaxInactiveInterval( int interval ) ; 7. ServletContext getServletContext() ; 8. HttpSessionContext getSessionContext() ; 9. Object getValue( String name ) ; 10. String[] getValueNames() ; 11. void invalidate() ; 12. boolean isNew() ; 13. void pubValue( String name, Object value ) ; 14. void removeValue( String name ) ; 15. void setAttribute( String name, String value ) ; 16. void setMaxInactiveInterval( int interval ) ; 17. void removeAttribute( String name ) ;
方法: 2. Object getAttribute( String name, int scope ) ; 3. Object findAttribute( String name ) ; 4. void removeAttribute( String name, int scope ) ; 5. void forward( String url ) ; 6. Enumeration getAttributeNamesScope( int scope ) ; 7. int getAttributeScope( String name ) ; 8. ErrorData getErrorDate() ; 9. Exception getException() ; 10. ExpressionEvaluator getExpressionEvaluator() ; 11. JspWriter getOut() ; 12. Object getPage() ; 13. ServletRequest getRequest() ; 14. ServletResponse getResponse() ; 15. ServletConfig getConfig() ; 16. ServletContext getServletContext() ; 17. HttpSession getSession() ; 18. VariableResolver getVariableResolver() ; 19. void include( String url, boolean flush ) ; 20. void release() ; 21. void initialize( Servlet servlet, ServletRequest request, ServletResponse response, 22. BodyContext pushBody() ; 23. JspWrite popBody() ; 24. void handlePageException( Exception e ) ; 成员:
方法: 2. Enumeration getAttributes() ; 3. ServletContext getContext( String uripath ) ; 4. String getInitParameter( String name ) ; 5. Enumeration getInitParameters() ; 6. int getMajorVersion() ; 7. String getMimeType( String file ) ; 8. int getMinorVersion() ; 9. String getRealPath( String path ) ; 10. RequestDispatcher getNamedDispatcher( String name ) ; 11. RequestDispatcher getRequestDispatcher( String path ) ; 12. URL getResource( String path ) ; 13. InputStream getResourceAsStream( String path ) ; 14. Set getResourcePaths( String path ) ; 15. String getServerInfo() ; 16. Servlet getServlet( String name ) ; 17. Enumeration getServlets() ; 18. String getServletContextName() ; 19. Enumeration getServletContextNames() ; 20. void log( Exception ex, String msg ) ; 21. void removeAttribute( String name ) ; 22. void setAttribute( String name, Object value ) ;
方法: 2. Enumeration getInitParameters() ; 3. ServletContext getContext() ; 4. String getServletName() ;
方法: 2. String getLocalizedMessage() ; 3. String getMessage() 4. StackTrackElement[] getStackTrace() ; 5. Throwable initCause( Throwable cause ) ; 7. void printStackTrace() ; 8. void setStackTrace( StackTraceElement[] stackTrace )
|
|
2F 唧唧 Post by : 2008-07-12 12:57:16.0
Request内置对象代表了客户端的请求信息,主要用于接受客户端通过HTTP协议传送给服务器端的数据。在客户端的请求中如果有参数,则该对象就有一个参数列表。它通常是HttpServlet-Request的子类,其作用域就是一次Request请求。Request对象包括很多方法,主要有:
getCookies():返回客户端的cookie对象,结果是一个cookie数组。 getSession(boolean create):返回和当前客户端请求相关联的HttpSession对象,如果当前客户端请求没有和任何HttpSession对象关联,那么当create变量为true,则创建一个HttpSession对象并返回;反之,返回null。 getHeader(String name):获得http协议定义的传送文件头信息 。 getAttribute(String name):返回name指定的属性值,若不存在指定的属性,就返回null。 getattributeNames():返回request对象所有属性的名字,结果集是一个Enumeration(枚举)类的实例。 getHeaderNames():返回所有request header的名字,结果集是一个Enumeration(枚举)类的实例。 getHeaders(String name):返回指定名字的request header的所有值,结果集是一个Enumeration(枚举)类的实例。 getMethod():返回客户端向服务器端传送数据的方法,一般方法有GET、POST、PUT等类型。 getParameter(String name):以字符串的形式返回客户端传来的某一个请求参数的值,该参数名由name指定。当传递给此方法的参数名没有实际参数与之对应时,返回null。 getparameterNames():返回客户端传送给服务器端的所有的参数名,结果集是一个Enumeration(枚举)类的实例。当传递给此方法的参数名没有实际参数与之对应时,返回null。 getParameterValues(String name):以字符串数组的形式返回指定参数所有值。 getQueryString():返回查询字符串,该字符串由客户端以GET方法向服务器端传送。 getRequestURI():获得发出请求字符串的客户端地址。 getServletPath():获得客户端所请求的脚本文件的文件路径。 setAttribute(String name,Java.lang.Object o):设定名字为name的request参数值,该值由Object类型的o指定。 getServerName():获得服务器的名字,如果没有设定服务器名,则返回服务器IP地址。 getServerPort():获得服务器的端口号。 getRemoteAddr():获得客户端的IP地址。 getRemoteHost():获得客户端主机的名字,若失败,则返回客户端电脑的IP地址。 getProtocol():获取客户端向服务器端传送数据所依据的协议名称,如http/1.1。 getContentLength():以字节为单位返回客户端请求的大小。如果无法得到该请求的大小,则返回-1。 getContentType():获取客户端请求的MIME类型。如果无法得到该请求的MIME类型,那么返回-1。 getInputStream():以二进制的形式将客户端的请求以一个ServletInputStream的形式返回。使用此方法可以获得客户端的multipart/form-data数据,可以实现文件上传。 isSecure():如果客户机是通过一个安全的访问方式访问的,就返回true;反之,返回false. getDateHeader():返回一个long类型的数据,表示客户端发送到服务器的头信息中的时间信息。 getInitHeader():获取客户端发送到服务器端的头信息中的某一个特定的信息,并转换为int类型。 getContextPath():返回环境路径。对于JSP来说,一般是当前Web应用程序的根目录。 isRequestedSessionIdValid():返回一个指示客户端请求发送Session ID是否仍然有效的布尔值。 isRequestedSessionIdFromCookie():返回一个指示客户端请求发送Session ID是否存在于Cookie中的布尔值。 isRequestedSessionIdFromURL():返回一个指示客户端请求发送Session ID是否存在于URL中的布尔值。 Response对象实现HttpServletResponse接口,可对客户的请求做出动态的响应,向客户端发送数据,如Cookie、HTTP文件头信息等,一般是HttpServlet.Response类或其子类的一个对象。该对象的常用方法为: addCookie(Cookie cookie):添加一个Cookie对象,用来保存客户端的用户信息,用request的getCookies()方法可以获得这个Cookie。 addHeader(String name,String value):添加HTTP文件头,该header将会传到客户端去,如果有同名的header存在,那么原来的header将会被覆盖掉。 containsHeader(String name):判断指定名字的HTTP文件头是否存在,并返回布尔值。 sendError(int sc):向客户端发送错误信息,例如,505指示服务器内部错误;404指示网页找不到的错误。 setHeader(String name,String value):设定指定名字的HTTP文件头的值,如果该值存在,那么它会被新的值覆盖。 setContenType(String type):响应设置内容类型头。 sendRedirect(URL):可以将用户重定向到一个不同的页面(URL)。sendRedirect(URL)方法通过返回特定的状态代码而起作用,当它被调用时,返回一个状态代码,然后在响应中定位,给新页面一个新地址。状态代码和定位头会自动把浏览器重定位到新页面。不过,用户通常不能被顺利重定位到新的页而,特别是老一些的浏览器,而且一些新版本的浏览器在自动响应定向作用状态代码时会有些问题,当浏览器无法自动响应状态代码时,会收到一些字段信息。 Session是一种服务器个别处理与记录用户端上网使用者信息的技术。当使用者与服务器联机时,服务器可以给每一个上网的使用者一个Session并设定其中的内容,这些Session都是个别独立的,服务器端可以借此来辨别使用者信息进而提供个别的服务。 Session对象的常用方法为: getAttribute(String name):获得指定名字的属性,如果该属性不存在,将会返回null。 getAttributeNames():返回Session对象中存储的每个属性对象,结果集是一个Enumeration类的实例。 setAttribute(String name,java.lang.Object value):设定指定名字的属性值,并且把它存储在Session对象中。 isNew():判断目前Session是否为新的Session,若是则返回ture,否则返回false。 getId():返回Session对象在服务器端的编号。每生成一个Session对象,服务器都会给它一个编号,并且该编号不会重复,这样服务器才能根据编号来识别Session,并且正确的处理某一特定的Session及其提供的服务。 getCreationTime():返回Session对象被创建的时间,单位为毫秒。 getLastAccessedTime():返回当前Session对象最后一次被操作的时间,时间的单位为毫秒。 getMaxInactiveInterval():获取Session对象的生存时间,时间的单位为秒。 setMaxInactiveInterval(int interval):设置Session的有效时间(也叫超时时间),时间的单位为秒。 removeAttribute(String name)“删除指定的属性(包含属性名、属性值)。如果在有效时间内,用户做出了新的请求,那么服务器就会将其看作一个新的用户,此时,服务器将创建一个新的Session,旧的Session信息将会丢失 |
| 风信Java论坛 ›› J2EE/Java Web 讨论交流中心 ›› JSP内建对象 | 登录 -> 注册 |