请求生命周期:

基于上述数据图,可以解释用户的请求的生命周期在Struts 2如下所示:

  1. 用户发送请求到服务器,用于请求对某些资源(即页).

  2. FilterDispatcher排着眼于该请求,然后确定适当的Action.

  3. 配置拦截器的功能适用于如验证,文件上传等。

  4. 选择的动作执行,执行所请求的操作。

  5. 同样,配置拦截器做任何后期处理,如果需要的话。

  6. 最后的结果是由视图准备,并且将结果返回给用户。

Struts 2 Hello World 实例:

从中学到了Struts 2的架构,当你点击一个超链接或提交一个Struts2的Web应用程序的HTML表单中,输入被发送到一个Java类操作的控制器,收集。执行该操作后,结果选择了一个资源来呈现的响应。资源通常是一个JSP,但它也可以是一个PDF文件,Excel电子表格,或Java小应用程序窗口。

假设你已经建立您的开发环境。现在,让我们继续建立我们的第一个Hello World struts2的项目。这个项目的目的是建立一个Web应用程序,收集用户的username,并显示“Hello World”,后面的用户名。我们将创建任何Struts2项目的四个组成部分:

SN 组件&描述
1 Action
Create an action class which will contain complete business logic and conrol the interaction between the user, the model, and the view.
2 Interceptors
Create interceptors if required, or use existing interceptors. This is part of Controller.
3 View
Create a JSPs to interact with the user to take input and to present the final messages.
4 Configuration Files
Create configuration files to couple the Action, View and Controllers. These files are struts.xml, web.xml, struts.properties.

我要使用Eclipse IDE,所以下创建一个动态Web项目所需的所有组件。因此,让我们开始创建动态Web项目。

猜你喜欢

转载自www.cnblogs.com/borter/p/9502106.html