在构建一个简单的基于MVC模式的JavaWeb 中,我们使用了JSP+Servlet+JavaBean构建了一个基于MVC模式的简单登录系统,但在其小结中已经指出,这种模式下的Controller 和 View有紧密的耦合度,因为在Controller代码中夹杂了组件部份的名称!
那么在这一篇我,我再改用Struts框架来构建这个系统,要注意的是,构建Struts应用程序时,一般不用自己去写中心控制器ActionServlet代码,因为ActionServlet是Struts框架的一个内置组件。但我们需要编写ActionForm和Action等组件的代码。
开发步骤如下:
Step1:设计数据表,与构建一个简单的基于MVC模式的JavaWeb 里面的表相同。
Step2:构建JSP页面,注意要把JSP中的HTML梅花鹿改为Struts特有的标记。
Step3:构建ActionForm,ActionForm其实是一个JavaBean,可以手工编写它,也可以使用工具生成!
Step4:构建Action,可以手工编写,也可以用工具!
Step5:构建模型组件和数据访问组件,与构建一个简单的基于MVC模式的JavaWeb 的相同!
Step6:构建Struts配置文件!
Step7:编译,打包,部署!
详细设计:
A:构建视图组件JSP页面,可以直接COPY构建一个简单的基于MVC模式的JavaWeb 中的三个页面,我们仅仅修改login.jsp页面,引入Struts标记,如下:















B:构建数据访问组件,与构建一个简单的基于MVC模式的JavaWeb 一样,COPY过来
C:构建模型组件LoginHanlder,与构建一个简单的基于MVC模式的JavaWeb 一样,COPY!
D:构建ActionForm,代码如下:
































































































































F:构建Struts的配置文件


































WEB配置文件




























