Struts2入门与Action配置实践

需积分: 9 1 下载量 113 浏览量 更新于2024-08-18 收藏 716KB PPT 举报
本文档主要介绍了如何使用Struts2进行Java Web开发,尤其是MVC模式下的应用。Struts2是一个流行的Web框架,它遵循模型-视图-控制器(Model-View-Controller,MVC)架构,帮助开发者简化前端与后端的交互,提供了一套高度可配置的解决方案。 首先,文章强调了MVC模式在Web开发中的重要性,它是将应用程序划分为三个独立部分:模型(Model)、视图(View)和控制器(Controller)。模型负责数据处理和业务逻辑,视图负责数据的展示,而控制器则作为两者之间的桥梁,接收用户请求并决定如何响应。 在Struts2中,开发者创建一个web工程,需要将下载的Struts2.3.8库中的jar包放置到WEB-INF/lib目录下,确保所有必要的插件和依赖已包含。接下来,创建一个名为loginAction的Action类,继承自ActionSupport类,用于处理网页事件响应,重写execute方法以实现特定的业务逻辑,如返回字符串"success"。 配置struts.xml文件是关键步骤,这里定义了一个名为loginpackage的包,其动作(action)是LoginAction,通过指定class属性连接到实际的Action类。当用户提交表单时,如果验证通过,将跳转到result标签指定的"next.html"页面。 最后,文档提到在web.xml中配置filter,这通常是将Struts2的拦截器和过滤器整合到整个应用生命周期中的过程,以便Struts2能有效地管理和处理HTTP请求和响应。 这篇文档为初学者提供了入门Struts2开发的基础教程,包括MVC模式的理解、Action的创建、配置文件的编写以及如何将Struts2框架融入到实际的web项目中。通过这些步骤,开发者能够构建出结构清晰、功能强大的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 上传