`

Struts2注解的使用

阅读更多
个人日记
LoginAction
package com.sunny.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
import com.sunny.entity.Users;

@ParentPackage("custom-default")
@Namespace("/user")
// 公共异常捕获
@ExceptionMappings({ @ExceptionMapping(exception = "java.lang.Exception", result = "exception") })
// 拦截器
@InterceptorRefs({ @InterceptorRef("annotatedStack") })
public class LoginAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Users users;

	public Users getUsers() {
		return users;
	}

	public void setUsers(Users users) {
		this.users = users;
	}

	@Action(value = "loginUser", results = {
			@Result(name = "success", location = "/a.jsp"),
			@Result(name = "error", location = "/index.jsp") })
	@Override
	public String execute() {
		if (users.getUsername().equals("sunny")
				&& users.getPassword().equals("sunny")) {
			return "success";
		} else {
			return "error";
		}
	}

	@Override
	public void validate() {
		if (users.getUsername().length() == 0) {
			addFieldError("username", "用户名不能为空");
		} else if (!users.getUsername().equals("sunny")) {
			addFieldError("username", "无效的用户名");
		}
		if (users.getPassword().length() == 0) {
			addFieldError("password", "密码不能为空");
		}
	}
}
分享到:
评论

相关推荐

    Struts2注解使用说明文档

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    struts2注解使用.doc

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    Struts2注解使用说明

    使用注解可以用来替换struts.xml配置文件!

    Struts2注解详细说明文档

    Struts2注解详细说明文档,详细讲述struts2的注解使用

    Maven实现struts2注解

    Maven实现struts2注解

    struts2注解与拦截器demo

    该例子为struts2注解与拦截器demo,利用myEclipse8.5开发,导入刚才后,自动加载所需struts2的jar包,可以直接运行,是初学struts2注解、拦截器很好的例子,保证10分钟学会2种技术,愿意分享给大家。

    struts2注解详解

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...

    Struts2注解开发jar

    Struts2注解开发jar,必须导入struts2-convention-plugin-2.3.15.jar包,它在struts2安装包下lib目录中。

    struts2注解登陆

    注解实现的页面跳转其特点是不用配置文件struts.xml因而可以实现零配置,同时由于有注解的功能,所以说大大增加了程序的可维护性。

    Struts2 注解 Demo

    Struts2Demo 注解的小例子,jar包全包括

    Struts 2使用注解配置Action

    Struts 2使用注解配置Action,不配置struts.xml,通过注解直接配置action

    struts2利用注解annotation实现文件下载

    本文档对利用struts2 注解 annotation 实现文件下载作了简单介绍,并有代码为例,希望对学习struts2注解annotation的人有帮助,特别是需要动态传参方面。

    Struts2+spring注解配置

    Struts2+spring注解配置 很好哦

    struts2注解必须包

    struts2-convention-plugin-2.1.8.1.jar

    struts2注解配置

    struts2 注解 配置 资料 最近学习struts2的注解配置,从网上找的一些资料,分享给大家。

    struts2 annotation 注解使用

    struts2 annotation 注解的详细介绍及使用方法

    maven整合struts2全注解

    maven整合struts2全注解,

    spring和Struts2注解文档

    spring和struts2注解讲解说明和使用

    struts2注解配置全面解析

    很多人在学习struts2注解的时候,都被它莫名其妙的错误搞的郁闷,而网上关于这方面的东西大多都是基于struts2.0版本的,对我们现在用的2.1以上的版本不起什么作用,所以特整理出一份文档,里面详细说明了怎样用注解...

Global site tag (gtag.js) - Google Analytics