Struts的核心组件
1.主要内容:
• Struts应用的配置:web.xml和strutsconfig.xml
• Struts的控制器组件
• Struts的模型组件
• Struts的视图组件
• Struts框架的扩展方法
• Struts的控制器组件
• Struts的模型组件
• Struts的视图组件
• Struts框架的扩展方法
2.Struts应用的web.xml文件
• (1)配置ActionServlet
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servletclass>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
• (1)配置ActionServlet
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servletclass>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
(2)声明ActionServlet的初始化参数:
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</paramvalue>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</paramvalue>
</init-param>
(3)配置欢迎文件清单
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
(4)配置错误处理
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
<error-page>
<exceptiontype> javax.servlet.ServletException </exception-type>
<location>/common/system_error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
<error-page>
<exceptiontype> javax.servlet.ServletException </exception-type>
<location>/common/system_error.jsp</location>
</error-page>
(5)配置Struts标签库
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</tagliblocation>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</tagliblocation>
</taglib>