cf.
http://foo.com/register.do?user=taro&mail=taro@foo.com&pass=PASS
res.setStatus( HttpServletResponse.SC_MOVED_PERMANENTLY); res.setHeader( “Location” , “http://backup1.foo.com/” );eq.
res.sendRedirect(“http://backup1.foo.com/” );
| 実装 | メソッド | 解説 | |
| REQUEST LINEにアクセス(ex. "GET http://localhost:8080/SJCWC/index.jsp?key1=value1&key2=1 HTTP/1.1") | |||
| 子 | String | getMethod() | (ex. "GET") |
| 子 | String | getContextPath?() | (ex. "/SJCWC" ) |
| 子 | String | getQueryString?() | (ex. "key1=value1&key2=value2") |
| 子 | String | getRequestURI() | (ex. "/SJCWC/index.jsp") |
| 子 | StringBuffer? | getRequestURL() | (ex. "http://localhost:8080/SJCWC/index.jsp") |
| 子 | String | getServletPath?() | (ex. "/index.jsp") |
| 子 | String | getPathInfo?() | 本来はコンテキストルートのフルパス(ex. "/srv/www/htdocs/") Tomcat 5.5では null が返る |
| 子 | String | getPathTranslated?() | 本来はリクエストされたファイルのフルパス (ex. "/srv/www/htdocs/SJCWC/index.jsp") Tomcat 5.5では null が返る |
| 親 | String | getProtocol() | (ex. "HTTP/1.1") |
| HTTP REQUEST HEADER にアクセス | |||
| 子 | Enumeration | getHeaderNames?() | |
| 子 | String | getHeader(String name) | |
| 子 | int | getIntHeader?(String name) | |
| 子 | long | getDateHeader?(String name) | |
| 子 | Enumeration | getHeaders(String name) | |
| 親 | int | getContentLength?() | |
| 親 | String | getContentType?() | |
| 親 | Locale | getLocale() | |
| 親 | Enumeration | getLocales() | |
| HTTP REQUEST BODY にアクセス | |||
| 親 | ServletInputStream? | getInputStream?() | |
| 親 | BufferedReader? | getReader() | getReader() を使うと、getParameter()は使えなくなる。逆にgetParameter()で一つでもパラメータを取り出すと getReader()は使えなくなる。 |
| 親 | String | getParameter(String name) | |
| 親 | Map | getParameterMap?() | |
| 親 | Enumeration | getParameterNames?() | |
| 親 | String[] | getParameterValues?(String name) | |
| User情報にアクセス | |||
| 子 | String | getAuthType?() | null(認証されていない)、BASIC_AUTH、CLIENT_CERT_AUTH、DIGEST_AUTH、FORM_AUTH |
| 子 | String | getRemoteUser?() | |
| 子 | Principal | getUserPrincipal?() | ユーザ名は java.security.Principal#getName() で得られる |
| 子 | boolean | isUserInRole?(String role) | ユーザは指定されたロールに属すか?(ユーザがどのロールに属すかを返すメソッドはJ2EEでは未定義) |
| Cookie情報にアクセス | |||
| 子 | Cookie[] | getCookies() | |
| Session領域を取得 | |||
| 子 | HttpSession | getSession(boolean create) | create=true : Sessionオブジェクトが無いときには新たに作る。create=false : Sessionオブジェクトが無いときには null が返る |
| 子 | HttpSession | getSession() | getSession(true) と同じ |
| Session管理(コンテナやフレームワークが使う) | |||
| 子 | String | getRequestedSessionId?() | |
| 子 | boolean | isRequestedSessionIdFromCookie?() | |
| 子 | boolean | isRequestedSessionIdFromURL() | |
| 子 | boolean | isRequestedSessionIdValid?() | |
| Request領域の操作 | |||
| 親 | Enumeration | getAttributeNames?() | |
| 親 | Object | getAttribute(String name) | |
| 親 | void | removeAttribute(String name) | |
| 親 | void | setAttribute(String name, Object o) | |
| その他 | |||
| 親 | String | getCharacterEncoding?() | |
| 親 | void | setCharacterEncoding?(String env) | |
| 親 | String | getRemoteAddr?() | |
| 親 | String | getRemoteHost?() | |
| 親 | String | getScheme() | ftp、http、httpsなどを返す |
| 親 | String | getServerName?() | |
| 親 | int | getServerPort?() | |
| 親 | boolean | isSecure() | https のとき true 、http のとき false |
| 親 | RequestDispatcher | getRequestDispatcher?(String path) | web.xmlで、pathに割り付けた、RequestDispatcher を返す |
| 実装 | メソッド | 解説 | |
| HTTP RESPONSE STATUS LINE にアクセス | |||
| 子 | void | setStatus(int sc) | |
| 子 | void | sendError(int sc) | |
| 子 | void | sendError(int sc, String msg) | |
| 子 | void | sendRedirect(String location) | |
| 子 | String | encodeRedirectURL(String url) | sendRedirect メソッドの引数を作る。リダイレクト先 url に "&jsessionid=${Session ID}" を埋目込む |
| HTTP RESPONSE HEADER にアクセス | |||
| 子 | void | addHeader(String name, String value) | |
| 子 | void | addIntHeader?(String name, int value) | |
| 子 | void | addDateHeader?(String name, long date) | |
| 子 | void | setHeader(String name, String value) | |
| 子 | void | setDateHeader?(String name, long date) | |
| 子 | void | setIntHeader?(String name, int value) | |
| 子 | boolean | containsHeader(String name) | |
| 親 | void | setContentLength?(int len) | |
| 親 | void | setContentType?(String type) | "Content-Type: text/html; charset=EUC-JP" |
| 親 | String | getCharacterEncoding?() | "Content-Type: text/html; charset=EUC-JP" の charset を得る |
| 親 | void | setLocale(Locale loc) | |
| 親 | Locale | getLocale() | |
| HTTP RESPONSE MESSAGE BODY にアクセス | |||
| 子 | String | encodeURL(String url) | HTTP文書の加工。url に "&jsessionid=${Session ID}" を埋目込む |
| 親 | ServletOutputStream? | getOutputStream?() | バイナリを MESSAGE BODY として出力( jpeg など ) |
| 親 | PrintWriter? | getWriter() | テキストを MESSAGE BODY として出力( html など ) |
| 親 | void | setBufferSize?(int size) | |
| 親 | int | getBufferSize?() | |
| 親 | void | flushBuffer() | |
| 親 | boolean | isCommitted() | |
| 親 | void | reset() | HTTP RESPONSE HEADER( Status Code )をクリアして、バッファの内容をクリア。STATUS , HEADER を書き換えるときには、まずこのメソッドを実行 (J2EEコンテナが規定値を設定しているから) |
| 親 | void | resetBuffer() | HTTP RESPONSE HEADER( Status Code )をクリアせずに、バッファの内容をクリア。Content-Type を書き換えて HTML文書 以外をクライアントに返信するときに使う |
| Cookie にアクセス | |||
| 子 | void | addCookie(Cookie cookie) | |
| 実装 | メソッド | 解説 | |
| Session領域を操作 | |||
| Enumeration | getAttributeNames?() | ||
| Object | getAttribute(String name) | ||
| void | removeAttribute(String name) | ||
| void | setAttribute(String name, Object o) | ||
| タイムアウト処理 | |||
| long | getCreationTime?() | Session開始時刻 | |
| long | getLastAccessedTime?() | 最終アクセス時刻 | |
| int | getMaxInactiveInterval?() | タイムアウト間隔(web.xml の <session-config><session-timeout>分</session-timeout></session-config>で指定したものの秒数) | |
| void | setMaxInactiveInterval?(int interval) | タイムアウト間隔(秒数指定) | |
| Session管理 | |||
| void | invalidate() | セッションの無効化。→ HttpSessionBindingListener#valueUnbound() | |
| boolean | isNew() | ||
| String | getId() | ||
| ServletContext領域取得 | |||
| ServletContext | getServletContext() | ||
| 実装 | メソッド | 解説 | |
| J2EEコンテナ情報 | |||
| String | getServerInfo?() | ||
| int | getMajorVersion?() | ||
| int | getMinorVersion?() | ||
| アプリケーション共有メモリ領域 | |||
| Enumeration | getAttributeNames?() | ||
| void | setAttribute(String name, Object object) | ||
| Object | getAttribute(String name) | ||
| void | removeAttribute(String name) | ||
| アプリケーション初期化情報(cf.付録) | |||
| ServletContext? | getContext(String uripath) | 他のServletContext?を得る | |
| String | getInitParameter?(String name) | web.xmlの<context-param>に記述された設定値を得る | |
| Enumeration | getInitParameterNames?() | web.xmlの<context-param>に記述された設定値を得る | |
| String | getServletContextName?() | web.xmlの<display-name>で定義された名前 | |
| Webアプリケーション情報・ユーティリティ | |||
| String | getRealPath?(String path) | 相対パスpathの絶対パス(URL)を得る | |
| URL | getResource(String path) | 相対パスpathの絶対パス(URL)を得る | |
| Set | getResourcePaths?(String path) | 相対パスpath以下の相対パス(URL)を得る | |
| InputStream? | getResourceAsStream?(String path) | webアプリ内のファイルを得る | |
| String | getMimeType?(String file) | ファイル名fileのMIME型。web.xmlの<mime-mapping> で定義されたMIMEタイプ。不明の場合はnull。 | |
| void | log(String msg) | ||
| void | log(String message, Throwable throwable) | ||
| RequestDispatcher? | getNamedDispatcher?(String name) | ||
| RequestDispatcher? | getRequestDispatcher?(String path) | ||
| リスナ | イベント処理メソッド | イベントの属性 |
| ServletContext?変更時 | ||
| ServletContextListener? | void contextInitialized(ServletContextEvent? event) | event#getServletContext?() |
| void contextDestroyed(ServletContextEvent? event) | ||
| ServletContextAttributeListener? | void attributeAdded(ServletContextAttributeEvent? event) | event#getName() , event#getValue() |
| void attributeRemoved(ServletContextAttributeEvent? event) | ||
| void attributeReplaced(ServletContextAttributeEvent? event) | ||
| ServletRequest?変更時 | ||
| ServletRequestListener? | void RequestInitialized?(ServletRequestEvent? event) | event#getServletContext?() , event#getServletRequest?() |
| void RequestDestroyed?(ServletRequestEvent? event) | ||
| ServletRequestAttributeListener? | void attributeAdded(ServletRequestAttributeEvent? event) | event#getName() , event#getValue() |
| void attributeRemoved(ServletRequestAttributeEvent? event) | ||
| void attributeReplaced(ServletRequestAttributeEvent? event) | ||
| HttpSession?変更時 | ||
| HttpSessionListener? | void sessionCreated(HttpSessionEvent? event) | event#getSession() |
| void sessionDestroyed(HttpSessionEvent? event) | ||
| HttpSessionAttributeListener? | void attributeAdded(HttpSessionBindingEvent? event) | event#getName() , event#getValue() , event#getSession() |
| void attributeRemoved(HttpSessionBindingEvent? event) | ||
| void attributeReplaced(HttpSessionBindingEvent? event) | ||
| リスナ | イベント処理メソッド | イベントの属性 |
| HttpSession?変更時 | ||
| HttpSessionActivationListener? | void sessionDidActivate?(HttpSessionEvent? event) | event#getSession() |
| void sessionWillPassivate?(HttpSessionEvent? event) | ||
| HttpSessionBindingListener | void valueBound(HttpSessionBindingEvent? event) | event#getName() , event#getValue() , event#getSession() |
| void valueUnbound(HttpSessionBindingEvent? event) | ||
// JSPに描画するデータの格納
req.setAttribute("Order", orderBean);
req.setAttribute("Customer", customerBean);
req.setAttribute("Bill", billBean);
// JSP呼び出し
req.getRequestDispatcher("/pages/hoge.jsp").forward(req,res);
Filter#doFilter(req,res,chain){
ServletRequest reqW = new MyServlerRequestWrapper( req );
chain.doFileter( reqW , res )
}