DMI(Dynamic Method Invocation)动态方法调用

<script>
	function regist()
	{
		targetForm = document.forms[0];
		targetForm.action = "login!regist";//会替换表单定义的ACTION
	}
</script>

<form action="login" method="post">

<td><input type="submit" value="登录"/></td>
<td><input type="submit" value="注册" onClick="regist();"/></

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;

public class LoginRegistAction extends ActionSupport
{
	//封装用户请求参数的两个属性
	private String username;
	private String password;
	//封装处理结果的tip属性
	private String tip;
	//username属性对应的setter和getter方法
	public String getUsername()
	{
		return username;
	}
	public void setUsername(String username)
	{
		this.username = username;
	}
	//password属性对应的getter和setter方法
	public String getPassword()
	{
		return password;
	}
	public void setPassword(String password)
	{
		this.password = password;
	}
	//tip属性对应的setter和getter方法
	public String getTip()
	{
		return tip;
	}
	public void setTip(String tip)
	{
		this.tip = tip;
	}
	//Action包含的注册控制逻辑
	public String regist() throws Exception
	{
		ActionContext.getContext().getSession().put("user" , getUsername());
		setTip("恭喜您," + getUsername() + ",您已经注册成功!");
		return SUCCESS;
	}
	//Action默认包含的控制逻辑
	public String execute() throws Exception
	{
		if (getUsername().equals("scott")
			&& getPassword().equals("tiger") )
		{
			ActionContext.getContext().getSession().put("user" , getUsername());
			setTip("欢迎," + getUsername() + ",您已经登录成功!");
			return SUCCESS;
		}
		else
		{
			return ERROR;
		}
	}
}

猜你喜欢

转载自xiongjiajia.iteye.com/blog/1431236
dmi