But none of those frameworks are simple enough to me.
So we create a new one for Lucy IoC container.
Let me introduce Teeda2(T2), a simple "web base".
Only you need to create is view(like jsp or whatever you like) and POJO(we name Page).
Here is a sample.
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" errorPage="/error/debug.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>足し算画面</title>
</head>
<body>
<form action="/t2-samples/add" method="post">
<input type="text" name="arg1" />
<br />
<input type="text" name="arg2" />
<br />
<span>${result}</span><br />
<input type="submit" name="add" value="同一ページ"/>
<input type="submit" name="addAndMove" value="結果ページ"/>
</form>
</body>
</html>
@RequestScope
@Page("add")
public class AddPage {
@Default
public Navigation index(TeedaContext context) {
return Redirect.to("jsp/add.jsp");
}
@POST
@ActionParam
public Navigation add(TeedaContext context) {
Request request = context.getRequest();
Integer arg1 = Integer.valueOf(request.getParameter("arg1"));
Integer arg2 = Integer.valueOf(request.getParameter("arg2"));
request.setAttribute("arg1", arg1);
request.setAttribute("arg2", arg2);
request.setAttribute("result", new Integer(arg1.intValue() + arg2.intValue()));
return Forward.to("jsp/add.jsp");
}
@POST
@ActionParam
public Navigation addAndMove(TeedaContext context) {
Request request = context.getRequest();
Integer arg1 = Integer.valueOf(request.getParameter("arg1"));
Integer arg2 = Integer.valueOf(request.getParameter("arg2"));
request.setAttribute("result", new Integer(arg1.intValue() + arg2.intValue()));
return Forward.to("jsp/addResult.jsp");
}
}
So, how to bind jsp to AddPage.java?
It's really simple.We do a way to use URL like REST.
You see @Page annotation and there is "add". This is a part of URL.
So, you access like http://localhost:8080/whatever-context-path/add
then, T2 binds to AddPage.java.
To be continued.
No comments:
Post a Comment