DAO w/ Struts2

// ActionContextの取得
ActionContext context = ActionContext.getContext();
Map map = context.getContextMap();

// サーブレットコンテキストの取得
ServletContext application =
(ServletContext) map.getStrutsStatics.SERVLET_CONTEXT);

// WEBアプリケーションコンテキストの取得
WebApplicationContext applicationContext =
(WebApplicationContext) application.getAttribute
(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

// DAOの取得
DAO dao = (DAO) applicationContext.getBean("DAO");

// カテゴリ検索を実行
List result = dao.getList("getCategoryList", null);

ref:
http://www.h3.dion.ne.jp/~alpha-pz/misc2217.html

isDebugEnabled

isDebugEnabledで性能向上

logmsgで文字連結をする場合は、logging処理より文字連結処理が行われる。
means
不要な処理となり得る
depends on
----------
log4j.rootLogger=DEBUG
----------

so,
better to do 出力判定 before 文字連結処理
----------
if(isDebugEnabaled()){
log.debug("debuglog:"+hogehoge);
}
----------

ref:
http://struts.wasureppoi.com/util/05_is_debug.html

start struts2 with blank project

13 June 2007 - Apache Struts 2.0.8 GA release available
ref:
http://www.apachenews.org/archives/001004.html

dl from
http://struts.apache.org/download.cgi
get
struts-2.0.8-all.zip

find the blank project
struts-2.0.8\apps\struts2-blank-2.0.8.war

import it into eclipse

make sure its version
project-name\WebContent\META-INF\maven\org.apache.struts\struts2-blank\pom.properties

wake up tomcat and access
http://localhost:8080/struts2-blank-2.0.8/

useful references:
structure of struts2
http://struts.apache.org/2.x/docs/big-picture.html
Apache Struts 2 Documentation # Constant Configuration
http://struts.apache.org/2.x/docs/constant-configuration.html
free document
http://www.infoq.com/minibooks/starting-struts2
samples
http://nullpo.2log.net/home/struts2/

intro to struts

JSP1.1/Servlet2.2仕様で定義されたwebアプリケーションのためのFW
---------------
history:
1ハイパーテキストの時代
 webサーバは、静的HTML文書のみを提供していた
2CGIの時代
 NSAPI・ISAPI・FastCGIなどを用いて動的なコンテンツを提供
 サーバ負荷が高い
3JavaServletの時代
 プラットフォーム非依存
 高負荷に耐えるスケーラビリティ
 ビジネスロジックのFWがJ2EEとして仕様化
4Web層のFWが登場
 Struts、Turbine、Velocity、Tapestry、WebWork…
------------------
J2EE=JavaAPI仕様の企業用途向けセット
1.2、1.3、1.4仕様がある
------------------
J2EEの「仕様」を「実装」した製品
http://java.sun.com/j2ee/comppatibility.html
------------------



------------------
Commons-Logging
コンソールとC:\tomcat\seminar_log4jLogger.logにログが出力される
 ↓      ↓
stdout   rolling file
Log=interface
JDK LoggerやLog4JLoggerがLogをimpl
cf. Log4J manual

Top

HOME

09 | 2008/10 | 11
- - - 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 -

QR

name:
mail:
title:
body:

N/A