HttpServlet?#doXXX()

HttpResponse?の文字コード

HttpRequest?ヘッダの取得

EnumlationgetHeaderNames?()
StringgetHeader(header-name)
intgetIntHeader?(header-name)
longgetDateHeader?(header-name)
EnumlationgetHeaders(header-name)

HttpRequest? , HttpSession? , ServletContext? へのオブジェクトの格納・参照

voidsetAttribute(String,Object)
ObjectgetAttribute(String)
EnumlationgetAttributeNames?()
voidremoveAttribute(String)

主要なweb.xmlの要素

<?xml version="1.0" encoding="UTF-8"?> <web-app>

context-param *

String HttpServlet.getServletContext().getInitParameter("param-name");
Enumlation HttpServlet.getServletContext().getInitParameterNames();

filter *

filter-mapping *

listener *


ここに登録するもの

クラスイベント
ServletContextListener?ServletContext?の生成・消滅時
ServletRequestListener?ServletRequest?の生成・消滅時
HttpSessionListener?HttpSession?の生成・消滅時
voidxxxxInitialized(ServletContextEvent event)
void xxxxDestroyed(ServletContextEvent event)|
クラスイベント
ServletContextAttributeListener?ServletContext?の属性変更
ServletRequestAttributeListener?ServletRequest?の属性変更
HttpSessionAttributeListener?HttpSession?の属性変更
void attributeAdded(ServletContextAttributeEvent event)
void attributeRemoved(ServletContextAttributeEvent event)
void attributeReplaced(ServletContextAttributeEvent event)
 

ここに登録しないもの

クラスイベント
HttpSessionActivationListener?これを実装したクラスが登録されているHttpSession?が、メモリ不足によりHDDに退避(WillPassivate?)/復活(DidActivate?)されるとき
void sessionDidActivate(HttpSessionEvent event)
void sessionWillPassivate(HttpSessionEvent event)
クラスイベント
HttpSessionBindingListener?これを実装したクラスがHttpSession?に登録・削除されるとき(HttpSession?のタイムアウトによる消滅時)
void valueBound(HttpSessionBindingEvent event)
void valueUnbound(HttpSessionBindingEvent event)

servlet *

servlet-mapping *

session-config *


void HttpSession?.setMaxInactiveInterval?(int)セションタイムアウトまでの数を設定
int HttpSession?.getMaxInactiveInterval?()セションタイムアウトまでの数を取得
void HttpSession?.invalidate()セションタイムアウトを起こす
boolean HttpSession?.isNew()新しいセッションか?

mime-mapping *

welcome-file-list *

error-page *

jsp-config *

<taglib>
   <taglib-uri>/http://hondou.homedns.org/tags/snail.tld</taglib-uri>
   <taglib-location>/WEB-INF/snail.tld</taglib-location>
</taglib>
<jsp-property-group>
  <url-pattern>*.jsp</url-pattern>
  <include-prelude>/header.jsp</include-prelude>
  <include-coda>/footer.jsp<include-coda>
</jsp-property-group>

security-constraint *

login-config *

security-role *

この webアプリ で使うロールを列挙

web.xml の URL指定

セキュリティ用語

JSPシンタックス-XMLシンタックス

JSP SyntaxXML Syntax
<%-- ... --%><!-- ... -->
<%! ... %><jsp:declaration> ... </jsp:declaration>
<%@ include ... /><jsp:directive.include ... />
<%@ page ... /><jsp:dicectiove.page ... />
<%@ taglib uri="yyy" prefix="xxx" /><html xmlns:xxx="yyy"/> = <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:xxx="yyy" version="2.0>
<%= ... %><jsp:expression> ... </jsp:expression>
<% ... %><jsp:scriptlet> ... </jsp:scriptlet>
Template Data<jsp:text> ... </jsp:text>

pageディレクティブ

<%@ page language="java" %>
<%@ page extends="" %>
<%@ page import="java.lang.*,javax.servlet.*,javax.servlet.http.*,javax.servlet.jsp.*" %>
<%@ page session="true" %>
<%@ page buffer="8kb" %>
<%@ page autoFlash="true" %>
<%@ page isThreadSafe="true" %>
<%@ page info="" %>
<%@ page isErrorPage="false" %>
<%@ page errorPage="" %>
<%@ page contentType="text/html;charset=ISO-8859-1" %>
<%@ page pageEncoding="contentTypeのcharset" %>
<%@ page isELIgnored="false" %>

<%@ include> , <jsp:include> , <c:import> , <%@ forward> , <jsp:forward> , <c:redirect>

JSP暗黙オブジェクト,EL暗黙オブジェクト,EL予約語

EL式を使えるところ使えないところ

場所
EL式を使えるところ
テンプレートテキスト。<FONT COLOR="RED">本日${count}人目のお客様</FONT>
ディレクティブの属性値<%@ page pageEncoding="${charset}" %>
アクション(タグ)の属性値<snail:code value="${code}"/>
EL式を使えないところ
スクリプトレット <% if(a=${count}){
宣言 <%! int flag = ${count>10}; %>
JSP式 <%= ${count} %>

EL式でMapからの値の取り出し

EL式で配列pからの値の取り出し

EL式で文字列との大小比較

EL式のempty演算子がtrueになるとき

${empty null}null
${empty ""}空文字
${empty new ArrayList?()}空のCollection
${empty new HashMap?()}空のMap
${empty int[0]}要素数0の配列

<jsp:useBean> type,class,beanName属性の組み合わせ

属性if scope.getAttribute("id")!=nullif scope.getAttribute("id")==null
classclass id=scope.getAttribute("id")type id=new class()
typetype id=scope.getAttribute("id")ERROR
class+typetype id=scope.getAttribute("id")type id=new class()
type+beanNametype id=scope.getAttribute("beanName")ERROR

<jsp:setProperty> の value,property属性

必須属性name
必須属性property
排他value即値、EL式の値を name.property に格納
paramHTTP REQUESTのパラメータを name.property に格納
(省略)<jsp:setProperty name="myBean" property="*"> とすると、HTTP REQUEST を myBean に自動転記

<c:set>

<c:out> の デフォルト値指定方法(2通り)

<c:out value="${val}">
  val is null
</c:out>
 
<c:out value="${val}" defalut="val is null">

<c:url>のパラメータ指定

<c:url value="/graph.do">
  <c:param name="xUnit" value="km"/>
  <c:param name="yUnit" value="degC"/>
</c:url>
 
/graph.do?xUnit=km&yUnit=degC

tagハンドラ継承関係

tagDiagram.png

tagハンドラのメソッドの返値

tld

<?xml version="1.0" encoding="UTF-8"?><taglib>

taglib-version ◇

必須項目なことに注意

short-name ◇

必須項目なことに注意

tag *

tag-file *

function *

タグファイル

J2EEパターン問題のキーワード

  1. Interceptiong Filter
    • 共通ロジックの局所化
    • 透過的な処理
    • 再利用性
  2. Front Controller
    • 共通ロジックの局所化
    • リクエストの一元管理
  3. Session Facade
    • ネットワークオーバーヘッドの減少
    • プレゼン層とビジネスロジックの疎結合
    • 共通ロジックの局所化
    • トランザクションの整合性
  4. Business Deligate
    • サービス固有のコードをクライアントから隠蔽
    • データのローカルキャッシング
    • モックオブジェクトへの切り替えが容易
    • トランザクションの透過的な再実行
  5. Service Locator
    • 煩雑な処理を局所化
    • アプリケーションのパフォーマンス向上(JNDI の look-up を毎回しない)
  6. DTO
    • アプリケーションのパフォーマンス向上

無効化したSessionから属性を取得しようとすると・・・

IllegalStateException? が起きる

<%@ page contentType="text/html;charset=Windows-31J" %>

<html>
<head>
  <title>Session Exam</title>
</head>

<body>

1.Sessionにkey属性を格納
<% session.setAttribute("key","val"); %>

<hr/>

2.Sessionのkey属性 = 
<%= session.getAttribute("key") %>

<hr/>

3.Session無効化
<% session.invalidate(); %>

<hr/>

4.Sessionのkey属性 = 
<%= session.getAttribute("key") %>

</body>

</html>
 
org.apache.jasper.JasperException: Exception in JSP: /SessionExam.jsp:26

23: <hr/>
24: 
25: 4.Sessionのkey属性 = 
26: <%= session.getAttribute("key") %>
27: 
28: </body>
29: 

原因

java.lang.IllegalStateException: getAttribute: セッションは既に無効化されています
org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1011)
org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:109)
	org.apache.jsp.SessionExam_jsp._jspService(SessionExam_jsp.java:70)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

本編

練習問題


Java


添付ファイル: filetagDiagram.png 2189件 [詳細]

トップ   編集 凍結解除 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2007-01-21 (日) 18:37:15 (6297d)
Short-URL: http://hondou.homedns.org/pukiwiki/pukiwiki.php?cmd=s&k=06620475b3
ISBN10
ISBN13
9784061426061