struts的action添加内置信息

package com.test.action;

import com.opensymphony.xwork2.ActionSupport;
import com.test.dao.UserCheck;
import com.test.vo.User;

public class LoginActionSupport extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public LoginActionSupport()
	{
		System.out.println("LoginActionSupport");
	}
	private String username;
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	private String password;
	
	public String execute()
	{
		User u=new User();
		u.setUsername(this.getUsername());
		u.setPassword(this.getPassword());
		
		/*调用业务逻辑层代码*/
		UserCheck check=new UserCheck();
		if(check.login(u))
		{
			return "login_ok";
		}
		else
		{
			this.addFieldError("error", "用户名或密码错误!");
			return "login_fail";
		}
		
	}
}

在JSP页面代码如下所示

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
登陆失败!<br>
<s:fielderror name="error" theme="simple"/>
</body>
</html>


输出页面


你可能感兴趣的:(struts的action添加内置信息)