Struts2初学

在web应用开发中,经常使用Struts框架来解决用户接口(UI)层及其与后端应用层之间的交互。

Struts框架是MVC设计模式的一个具体实现

1、基本Struts框架结构


2、Struts2工作基本流程


3、基本配置文件

 web.xml


struts.xml


Action.java


index.jsp


Action接口
	public static final java.lang.String SUCCESS = "scuccess";
	...... ERROR = "error";
	...... INPUT = "input";
	...... NONE = "none";
	...... LOGIN = "login";
	
Actionsupport继承
	1.实现了Action接口的基础上还定义了一个validate()方法,重写该方法,
	它会在execute()方法之前执行,如校验失败,会转入input处,必须在配置该Action时配置input属性。

	2.Actionsupport还提供了一个getValue(Object key)方法还实现国际化,该方法从资源文件上获取国际化信息
	
	action类中 
		execute()函数用于处理用户请求
		validate()函数用于校验数据
			this.addFieldError(object, value);
				将信息返回到页面的指定位置上
				【注】:
					1.要在struts.xml中指定<result name="input">/xx.jsp</result>
					不然会报错No result defined for action geekfly.action.LoginAction and result input
					2.object的值要与页面上的name匹配
				

猜你喜欢

转载自blog.csdn.net/qq_34819372/article/details/80381030