走进去看Struts——可“配置”的页面流转
一、Struts框架组件:
ActionServlet控制器
Action 包含事务逻辑
ActionForm 显示模块数据
ActionMapping 帮助控制器将请求映射到操作
ActionForward 用来指示操作转移的对象
ActionError 用来存储和回收错误
Struts Taglib 可以减轻开发显示层次的工作
二、进去看流程(可“配置”的页面流转)
仍以登录为例,程序包含以下主要文件:
web.xml,struts-config.xml,ActionForm.java,Action.java,jsp页面。
运行流程:
(1)开启服务器
(2)加载web.xml到内存
(3)根据web.xml加载ActionServlet,并读取struts-config.xml到内存。
web.xml
<?xml version="1.0"encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-beanname="loginForm"type="com.ys.struts.LoginActionForm"></form-bean> </form-beans> <action-mappings> <actionpath="/login" type="com.ys.struts.LoginAction" name="loginForm" scope="request"> <forwardname="success"path="/login_success.jsp"></forward> <forwardname="error" path="/login_error.jsp"></forward> </action> </action-mappings></struts-config>