Struts1.0初学者指南:框架解析与开发要点

4星 · 超过85%的资源 需积分: 0 3 下载量 130 浏览量 更新于2024-07-28 收藏 40KB DOC 举报
"Struts1.0学习文档-初学者入门" Struts1.0是一个开源的Java Web应用程序框架,它构建在Servlet和XML等Web开发标准之上,旨在解决传统Web应用开发中的复杂性问题,如代码重用、移植性和可维护性。Struts1.0遵循Model-View-Controller (MVC)设计模式,鼓励开发者采用Model2 MVC架构,尽管在实际应用中并不强制完全遵循。在Struts1.0稳定版本发布后,1.1测试开发版也相继推出。 **整体结构** Struts1.0框架的核心是ActionServlet,这是一个实现了控制器功能的Servlet。ActionServlet负责接收客户端的HTTP请求,并根据配置文件(struts-config.xml)将请求转发给相应的后台模型处理类。这种设计使得模型、视图和控制器之间能够解耦,增强了应用的灵活性和可维护性。配置文件struts-config.xml用于定义请求与处理类之间的映射,利用Java的类反射和请求过滤技术实现动态路由。视图层通常使用JSP和自定义标签库(Tag Libraries),通过扩展JSP标记来与模型数据建立联系。 **控制器** 控制器组件由Struts框架自身提供,具体实现为`org.apache.struts.action.ActionServlet`。开发者无需直接编写控制器类,只需要在web.xml中配置ActionServlet,并指定相应的映射规则。例如,`<servlet>`和`<servlet-mapping>`标签用于注册ActionServlet,而`<action>`标签则定义了请求路径与处理类的关系。此外,初始化参数如`application`用于指定全局属性文件的位置,这些文件用于存放应用级的消息资源。 **模型** 在Struts1.0中,模型分为系统状态模型和业务逻辑模型。系统状态模型通常通过Java Bean类来维护请求数据,这些Bean类通常继承自`org.apache.struts.action.ActionForm`,负责收集和验证用户输入。业务逻辑模型则是处理业务规则的类,它们不依赖于任何特定的视图技术,可以独立于Struts框架进行单元测试。业务逻辑类通常执行数据库操作、计算或其他复杂的业务流程。 **开发流程** 开发一个Struts1.0应用通常包括以下步骤: 1. **创建模型类**:定义ActionForm子类,用于封装表单数据。 2. **配置struts-config.xml**:映射URL到ActionForm类和Action类,设置国际化属性文件。 3. **编写Action类**:实现业务逻辑,处理ActionForm提交的数据,并决定转向哪个JSP页面。 4. **创建视图**:使用JSP和自定义标签库展示数据。 5. **部署应用**:将应用打包并部署到服务器,配置web.xml以启动ActionServlet。 Struts1.0为Java Web开发提供了一种规范化的结构,降低了复杂性,提高了代码复用和可扩展性。然而,随着技术的发展,Struts1.0逐渐被更新的框架如Spring MVC所取代,但仍不失为理解和学习MVC模式的一个重要参考。

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 上传

我用Spring5的aop应用时报这个错误Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:\ecliple\web5\WEB-INF\applicationContext.xml]; nested exception is java.nio.file.NoSuchFileException: WEB-INF\applicationContext.xml,他说我的applicationContext.xml文件不存在,可是我明明有这个文件,另外我的web.xml需要更改吗<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <context-param> <param-name>contextConfigLocation </param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <display-name>Struts2</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/* </url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>

2023-05-30 上传