アウトプットができる技術者に

it's a time to take a new step !

Struts2

Struts2 入門 Localization

package_ja.properties は action support の getText("foo") で取得できる pacakge_xx.properties は scope が package global_ja.properties は struts.xml の設定が必要 <constant name="struts.custom.i18n.resources" value="global" /> reference http://www.kobu.com/i18n/struts2/ http://www.tutorialspoint.com/str</constant>…

Struts2入門 validate

概要 複数方法があるっぽい - xml - annotation - Action Class に validate メソッドを記述 validate method を用いる方式 利用方法 Action Class に validate メソッドを書くと 自動で呼ばれる エラーがあった場合、"input"にforwardする validateを実行し…

Struts2 入門 Localization UI Tag

Localization = 国際化対応の話 text Tag で properteis ファイルにある文字列を出力できるjsp <s:text name="menu" /> package.propreties menu=menu_jp 引数を利用して format することも可能 jsp <s:text name="format.number_money"> <s:param name="value" value="sumValue"/> </s:text> package.properties format.number_money={0,number,#,##0}結果 2,270,00…</s:text>

Struts2 入門 LoginInterceptor 実装サンプル

Interceptor の 実装サンプルとして、Login認証を interceptor として実装 ここでは、convention plugin を導入前提として書いている サンプル処理の流れ 1. ユーザーによる http request 2. struts.xml の設定に従い、request 先の action に Login Interce…

Struts2 Result Annotation

2.1系以降?ではこんな感じ。typeを指定しないとdispatcherになる。 @Result(name = "login", location = "login") @Result(name = "stream", location = "InputStream", type = "stream", params = { "contentType", "image/png", "inputName", "inputStrea…

Struts2 HttpServlretReuqest / ServletContext の取得

ServletActionContextから取得できる。 Actionクラスでは RequestAware インタフェースを実装するのが普通。 HttpServletRequest request = ServletActionContext.getRequest(); System.out.println((String)request.getParameter("id")); // post/getパラメ…

Struts2 入門 convention plugin Debug設定

公式サイトによれば、下記でデバッグが出力されるとのこと。 でも、環境によって 出たり出なかったりするのは、何が原因なんだろう。。 JDK Loggerの場合 Loggingのレベルを Trace にする log4j の場合 log4j.logger.org.apache.struts2.convention=DEBUG st…

Struts2 session

action クラスにて、session aware interface を 実装することで利用できる 取得できるのは HttpSession ではなく、Map<String, Object> で <sessionのkey, 格納値> となる public class Basic extends ActionSupport implements SessionAware { private…

Struts2 struts.xml

書き方について 記述順があるので、注意が必要。 読み込まれる順番 core の struts-default.xml plugin の struts-plugin.xml webapp の struts.xml reference http://struts.apache.org/development/2.x/docs/strutsxml.html

Struts2 Interceptor

概要 Actionの前に実行する処理を interceptor として定義できる。 方法 AbstractInterceptor を extends したクラスを生成 intercept メソッドをオーバーライドする Login処理をInterceptorとして実装 reference http://codezine.jp/article/detail/5024 ht…

Struts2 入門 目次

基本 actionクラスでのsessionの使い方 Result Annotation struts.xml ActionContext validation Tag select Localization UI Tag Tips Interceptor Sessionのキャストを省略する convention plugin Debug設定

Sessionのキャストを省略する

Struts2でコーディングしているときに、ふと、、、sessionのキャスト省略できるんじゃ?と思いました。普通は、ActionクラスでSessionAwareを実装して下記のようにsessionから値を取得できます。 String a = (String) session.get("key");でもこれって、、い…