Struts2 (two) & struts2 other packaging methods described injection method & Explanation

The Servlet API access of the Struts2

In using the framework Struts2 found Struts2 and Servlet API is the decoupling. In the actual development, often used to the Servlet API, such as log in, the user will save the information to the Session, sometimes need to export some of the content to the page, use the response object. Related to visits to the Servlet API.

Completely decoupled manner

Write JSP
Here Insert Picture Descriptionto write Action
Here Insert Picture Description

注意:这种方式只能获得代表request、session、application的数据的Map集合,不能操作这些对象的本身的方法。

Servlet API using the native mode (*****)

Write JSP
Here Insert Picture Descriptionto write Action
Here Insert Picture Description

***** 注意:这种方式可以操作域对象的数据,同时也可以获得对象的方法。

Way interface injection

Write JSP
Here Insert Picture Description to write Action
Here Insert Picture Description

Servlet是单例的,多个程序访问同一个Servlet只会创建一个Servlet的实例。Action是多例的,一次请求,创建一个Action的实例(不会出现线程安全的问题)。

Struts2 configuration results page

Global results page

全局结果页面:全局结果页面指的是,在包中配置一次,其他的在这个包中的所有的action只要返回了这个值,都可以跳转到这个页面。
	针对这个包下的所有的action的配置都有效。

Here Insert Picture Description

Local results page

局部结果页面:局部结果页面指的是,只能在当前的action中的配置有效。
	针对当前的action有效

Here Insert Picture Description

Configuration result label

result标签用于配置页面的跳转。在result标签上有两个属性:
	name属性	:逻辑视图的名称。默认值:success
	type属性	:页面跳转的类型。
		dispatcher	:默认值,请求转发。(Action转发JSP)
		redirect	:重定向。(Action重定向JSP)
		chain		:转发。(Action转发Action)
		redirectAction	:重定向。(Action重定向Action)
		stream		:Struts2中提供文件下载的功能。

The data encapsulation Struts2

Struts2框架是一个web层框架,web层框架(框架:软件的办成品,完成一部分功能)。Struts2提供了数据封装的功能。

Driving property: attribute set method provides a way (not used)

Written pages
Here Insert Picture Descriptionwritten in Action
Here Insert Picture Description

Properties driving: page provides an expression way

Write JSP
Here Insert Picture Descriptionto write Action
Here Insert Picture Description

Driver Model: The model-driven mode (most common)

Write JSP
Here Insert Picture Descriptionto write Action
Here Insert Picture Description

模型驱动方式最常用的方式:
	缺点:只能同时向一个对象中封装数据。
使用第二种可以向多个对象中同时封装数据:

Configuring a logical view of INPUT

Action接口中提供了五个逻辑视图的名称:
	SUCCESS
	ERROR
	LOGIN
	INPUT	:input在某些拦截器中会使用。
	NONE

Complex types of data encapsulation Struts2

在实际开发中,有可能遇到批量向数据库中插入记录,需要在页面中将数据封装到集合中。

List encapsulated data collection

Write JSP
Here Insert Picture Descriptionto write Action
Here Insert Picture Description

Map data collection package

Write JSP
Here Insert Picture Description
to write Action
Here Insert Picture Description

Published 60 original articles · won praise 4 · Views 1270

Guess you like

Origin blog.csdn.net/qq_43966129/article/details/105202846