WebForm是事件驱动的,控件状态可以在http请求之间自动保持,并且使用后置代码很好地实现了页面外观与页面逻辑控制的分离,一改以往html,服务器段代码、javaScript混杂在一起的web开发方式。stucts提供了大量的定制标签,由tag、form、bean、action及配置文件构建了一个优秀的MVC模式的web开发方式。但相比较其WebForm来,窃以为stucts更为复杂,需要协同工作的元素较多,解决问题的效果不如WebForm显著(仅是个人看法)。
在现实开发中,常常需要在某个页面中处理很多Form控件,且要处理这个页面可能引发的多个事件,在事件触发后,又请求同一个页面,又需要在请求之间保持状态,在页面中处理所有这些,真实不胜其烦。受到WebForm启发,我在用JSP进行开发时,借鉴了了其一些思想。本质上我们就是想让页面显示代码与页面控制代码分离,要作到这一点并不困难,有很多办法。
可以为页面定义一个“页面处理器(PageHandler)”,它类似WebForm的后置代码,它的接口基本是下面这个样子:
public class PageHandler { protected HttpServletRequest request; protected HttpServletResponse response; protected JspWriter out; protected PageContext pageContext; protected HttpSession session = null; protected ServletContext application = null; protected ServletConfig config = null;
protected String event_action = null; //页面事件 protected String event_params = null; //页面参数
//取得操作页面的基本组件 public PageHandler(PageContext page) { this.pageContext = page; this.request = (HttpServletRequest) pageContext.getRequest(); this.response = (HttpServletResponse) pageContext.getResponse(); this.pageContext = page; out = pageContext.getOut(); application = pageContext.getServletContext(); config = [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>
|