オレオレJava Webフレームワークを作ってみる。その2

始まりはここ。

JSP(入力画面)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>input</title>
</head>
<body>
<h1>足し算 入力</h1>
<c:forEach var="v" items="${m.items}">
${f:h(v)}<br/>
</c:forEach>
<form>
<input type="text" ${f:text("arg1")} /> ${f:h(m.arg1)}<br/>
+<br/>
<input type="text" ${f:text("arg2")} /> ${f:h(m.arg2)}<br/>
<br/>
<input type="submit" name="calculate" />
</form>
</body>
</html>

基本slim3のパクリでJSTL+ELファンクションで作る感じ。
メッセージをまとめて出す部分は、共通のJSPに切り出すのがいいかも。
'm'はMapですが、m.itemsはCollectionで、m.arg1とかはStringという実装。。

JSP(結果画面)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>result</title>
</head>
<body>
<h1>足し算 結果</h1>
結果: ${f:h(result)}
</body>
</html>

message.xml

メッセージの定義ファイルです。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>message</comment>
<entry key="bind.error">{0}: 正しい形式で入力してください。</entry>
<entry key="validator.required">{0}: 必須です。</entry>
<entry key="validator.integerType">{0}: 整数で入力してください。</entry>
</properties>

通常のプロパティファイルは、native2ascciが必要でイラっとします。そのため、XML形式のプロパティファイルにしました。ResourceBundle経由で読み込むようにしてみた。

web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <display-name>Web Application</display-name>
      <filter>
        <filter-name>actionfilter</filter-name>
        <filter-class>org.selva2.webframework.ActionFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>actionfilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <el-ignored>false</el-ignored>
            <page-encoding>UTF-8</page-encoding>
            <scripting-invalid>false</scripting-invalid>
            <include-prelude>/WEB-INF/view/common.jsp</include-prelude>
        </jsp-property-group>
    </jsp-config>
</web-app>

サーブレットはなく、フィルターのみ。他のフレームワークのように、アプリケーションのベースとなるパッケージを指定できるが、デフォルトで、'webapp'を使う。

今日は、以上。