Struts2配置优化:拆分多个struts.xml文件

需积分: 0 1 下载量 116 浏览量 更新于2024-07-11 收藏 1.45MB PPT 举报
本文主要介绍如何在Struts2框架中指定并使用多个配置文件,以解决随着应用程序规模扩大,struts.xml文件变得庞大、难以管理的问题。Struts2是一个流行的MVC框架,提供了一系列用于Web应用程序开发的解决方案,包括页面导航、用户输入验证、统一布局、扩展性、国际化、Ajax支持以及防止表单重复提交等。 Struts2概述: Struts2是一个基于MVC模式的Java Web框架,用于构建高效且易于维护的应用程序。它为开发者提供了处理常见开发问题的方法,如动态页面导航、输入验证、统一的界面设计、框架的可扩展性、国际化的支持以及与Ajax的集成。Struts2还帮助防止表单的重复提交,确保应用的正确运行。 指定多个struts配置文件: 当应用中的Action数量增加时,单一的struts.xml配置文件会变得复杂且不易管理。为了解决这个问题,可以将配置分解到多个文件中,然后在主的struts.xml文件中通过`<include>`元素来包含这些子配置文件。例如: ```xml <struts> <include file="struts-user.xml"/> <include file="struts-order.xml"/> </struts> ``` 这样,每个子配置文件(如struts-user.xml和struts-order.xml)可以专注于特定的模块,使得配置更加清晰和模块化,提高代码的可读性和可维护性。 Struts2入门与环境搭建: 开始使用Struts2,需要创建一个Java Web工程,并准备相应的依赖库。可以从Apache官网下载Struts2的发行包,比如struts-2.x.x-all.zip,解压后在lib目录下获取必要的JAR文件。基础的Struts2开发通常需要以下JAR: 1. struts2-core-2.1.8.1.jar:Struts2框架核心库 2. xwork-core-2.1.6.jar:XWork基础库,Struts2在此之上构建 3. ognl-2.7.3.jar:对象图导航语言,用于读写对象属性 4. freemarker-2.3.15.jar:FreeMarker模板引擎,用于Struts2 UI标签 5. commons-logging-1.1.x.jar:日志包,支持Log4J和JDK 1.4+的日志记录 6. commons-fileupload-1.2.1.jar:文件上传组件 7. commons-io-1.3.2.jar:文件操作依赖的JAR 8. Commons-lang3-xxx.jar 和 Javassist-xxx.jar:其他辅助库 搭建环境的步骤包括: 1. 创建Java Web工程 2. 获取并引入所需的Struts2 JAR文件 3. 编写JSP页面 4. 创建Action类 5. 编写Struts2配置文件(struts.xml) 6. 在web.xml中配置Struts2 Filter,以启动Struts2框架 通过以上步骤,开发者可以建立起一个基本的Struts2开发环境,从而开始构建MVC结构的Web应用。

192.168.85.1 - - [26/Jun/2022:06:07:07 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 24 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 24 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 24 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 12925 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 12925 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 12925 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 14 192.168.85.1 - - [26/Jun/2022:06:08:06 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 15 192.168.85.1 - - [26/Jun/2022:06:08:16 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 1227 192.168.85.1 - - [26/Jun/2022:06:10:15 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 79 192.168.85.1 - - [26/Jun/2022:06:13:25 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 404 752 192.168.85.1 - - [26/Jun/2022:06:16:42 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 35 192.168.85.1 - - [26/Jun/2022:06:16:57 -0400] "GET //struts2-showcase/hhh.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:18:55 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 35 192.168.85.1 - - [26/Jun/2022:06:19:02 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 35 192.168.85.1 - - [26/Jun/2022:06:19:09 -0400] "GET //struts2-showcase/hhh1.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:19:34 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 400 192.168.85.1 - - [26/Jun/2022:06:20:37 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 5 192.168.85.1 - - [26/Jun/2022:06:20:42 -0400] "GET //struts2-showcase/hhh1.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:20:46 -0400] "GET //struts2-showcase/hhh.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:20:51 -0400] "GET /struts2-showcase/hhh.jsp HTTP/1.1" 403 642

2023-07-12 上传