Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1188708
  • 博文数量: 89
  • 博客积分: 10546
  • 博客等级: 上将
  • 技术积分: 1510
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-16 01:24
文章分类

全部博文(89)

文章存档

2012年(7)

2011年(4)

2010年(5)

2009年(52)

2008年(21)

分类: Java

2009-03-13 12:45:00

你现在已经创建第一个 helloworld 实例,并且能够在服务器运行起来,但是,helloworld 是如何在服务器上运行的呢?

你可能已经注意到,在 web.xml 我们注册一个 StripesFilterDispatcherServlet 。在我们熟悉的 web 框架中,如 Struts 1Struts 2 ,很少同时使用 Filter 和 Servlet 的。如在 Struts 1 中使用一个 ActionServlet 作为控制器,处理页面请求。在 Struts 2 中,使用了一个 Filter 处理所有请的请求。在 Stripes StripesFilter 主要是为请求处理作一些准备工作,它负责读取配置,处理 Locale ,并根据页面的 form 取得相应的 ServletWrapper 包装类。

你可以也注意到 StripesFilter 同时会过滤所有的 JSP 文件和 DispatcherServlet。 如果请求的是一个 jsp 页面,如我们的首页 index.jsp ,在 StripesFilter 处理完后会直接跳转到相应的JSP页面。如果请求是一个 ActionBean 的某个 event ,后续处理工作会交给 DispatcherServlet 来进行。

当 helloworld 运行起来之后,如果查看首页 index.jsp 的源代码,你会发现,在 stripes:form 标签中设置的 beanclass="tutorial.action.HelloActionBean",转换了 action="/helloworld/Hello.action"Stripes 根据自己规则为你生成了 URL

在 helloworld 程序中,index.jsp 提交时,DispatcherServlet 会根据 URL 来创建一个 ActionBean ,将 HttpServletRequest中的参数绑定 ActionBean 的属性上。然后执行相应的 event 对应的方法。而这 event 的名称正是 index.jsp 中页面 form 中提交按钮的 name 属性值。

[注意]注意
这里,我们跳过了一些细节没有提及,如数据类型转换,验证。以后会慢慢深入了解。



阅读(1413) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~