`
hh792000
  • 浏览: 16762 次
  • 性别: Icon_minigender_1
  • 来自: 通渭
社区版块
存档分类

struts2复习记录__简单登录

阅读更多
今日复习,发现好多知识点都已经很是模糊,决定以后认真复习,并记录之。
---struts2登录---

1、strust.xml内容:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<package name="defualt" namespace="/" extends="struts-default">
		<action name="login" class="com.he.action.LoginAction">
			<result name="success">success.jsp</result>
			<result name="input">login.jsp</result>
		</action>
	</package>
</struts>

2、login.jsp内容:
<body>
		<form action="login.action" method="post">
			<table border="1" cellpadding="0" cellspacing="0" bordercolor="red">
				<tr>
					<td>
						用户名
					</td>
					<td>
						<input type="text" name="username" />
					</td>
				</tr>
				<tr>
					<td>
						密&nbsp;&nbsp;码
					</td>
					<td>
						<input type="password" name="password" />
					</td>
				</tr>
				<tr>
					<td colspan="2" align="right">
						<input type="submit" value="login" />
					</td>
				</tr>
			</table>
		</form>
</body>

3、LoginAction.java内容:
package com.he.action;

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

public class LoginAction extends ActionSupport
{
	
	private String username ;
	private String password ;
	
	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;
	}
	public String execute() throws Exception
	{
		if(!username.equals("")&&!password.equals("") )
		{
			ActionContext.getContext().getSession().put("username", username);
			return Action.SUCCESS ;
		}else{
			return Action.INPUT ;
		}

	}
}

   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics