|
<html> |
//標準API
import java.io.*;
import java.util.HashMap;
//ServletAPI
import javax.servlet.*;
import javax.servlet.http.*;
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.printer.HttpPrinter;
import jp.kuro.ur.Request;
public class RequestServlet extends HttpServlet {
ParserFactory pf;
String path2;
Request anl;
public void init(ServletConfig sConf) throws ServletException {
ServletContext sc = sConf.getServletContext();
String path = sc.getRealPath("/WEB-INF/html/");
path2 = sc.getRealPath("/WEB-INF/");
pf = new ParserFactory(path);
pf.parser(Parser.HTML, "request.html", "Shift_JIS");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Parser xt = pf.parser("request");
anl = new Request();
anl.setCharacterEncoding("Shift_JIS");
HashMap query = anl.analyze(req).getQuery();
if (query.get("submit") != null && !query.get("submit").equals("")) {
Element tag = xt.element("name", "textfield");
Element tag2 = xt.element("name", "textfield2");
tag.attribute("value", (String) query.get("textfield"));
tag2.content((String) query.get("textfield2"));
}
//反映する
xt.flush();
HttpPrinter prt = new HttpPrinter(res);
prt.print(xt);
}
}
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> |
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.hook.Hooker;
//標準API
import java.util.*;
public class RequestLoop extends Hooker {
HashMap hmap;
public RequestLoop(HashMap query) {
this.hmap = query;
}
public void execute(Element xt) {
HashMap query = hmap;
//タグ検索
Element tag = xt.child("name", "param1");
Element tag2 = xt.child("name", "param2");
String param1;
String param2;
for (int j = 0; j < 3; j++) {
//表示ロジック
if (query.get("submit") != null) {
param1 = (String) ((ArrayList) query.get("param1")).get(j);
param2 = (String) ((ArrayList) query.get("param2")).get(j);
tag.clone().attribute("value", param1);
tag2.clone().attribute("value", param2);
}
//出力ロジック
xt.flush();
}
}
}
|
//標準API
import java.io.*;
import java.util.*;
//ServletAPI
import javax.servlet.*;
import javax.servlet.http.*;
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.printer.HttpPrinter;
import jp.kuro.ur.*;
public class RequestLoopServlet extends HttpServlet {
ParserFactory pf;
Request anl;
public void init(ServletConfig sConf) throws ServletException {
//"request2.html"の絶対パスを取得する
ServletContext sc = sConf.getServletContext();
String path = sc.getRealPath("/WEB-INF/html/");
//パーサファクトリオブジェクトを生成し、"request2.html"を読み込む
pf = new ParserFactory(path);
pf.parser(Parser.HTML, "request2.html", "Shift_JIS");
//リクエストオブジェクトを生成する
anl = new Request();
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//htオブジェクトのコピーを取得する
Parser xt = pf.parser("request2");
//リクエストのエンコーディングを指定する
anl.setCharacterEncoding("Shift_JIS");
//リクエストパラメータがマルチの場合の返却タイプを指定
anl.setMultiType(Request.MULTI_TYPE_LIST);
//リクエストのパラメータを取得する
HashMap query = anl.analyze(req).getQuery();
//赤字部分の動的ループのロジックを呼び出す。
Element tag = xt.element("tr", "name", "loop");
tag,execute(new RequestLoop(query));
//反映する
xt.flush();
//HTTP出力する。
HttpPrinter prt = new HttpPrinter(res);
prt.print(xt);
}
}
|