知识大全 实现login的两种方法
Posted 文件
篇首语:明明你一个人可以活的很开心的,偏偏非要学别人谈恋爱……本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 实现login的两种方法相关的知识,希望对你有一定的参考价值。
方式一 将VO的东西封装到Action里面
编写Action方法
package action;
import opensymphony xwork 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;
@Override
public String execute() throws Exception
if ( aaa equalsIgnoreCase(username)&& aaa equalsIgnoreCase(password))
return loginSuc ;
else
return loginFail ;
配置文件
<action name= mylogin class= action LoginAction >
<result name= input >/mylogin jsp</result>
<result name= loginSuc >/ok jsp</result>
<result name= loginFail >/errok jsp</result>
</action>
然后编写登录的JSP页面
<s:form action= mylogin action >
<table width= % align= center >
<tr>
<td>
<s:textfield key= username label= USERNAME />
</td>
</tr>
<tr>
<td>
<s:password key= password label= PASSWORD />
</td>
</tr>
<tr>
<td>
<s:submit value= SUBMIT />
</td>
</tr>
</table>
</s:form>
注意这里面的JSP里面的表单名称要与Action里面的名称保持一致的
也可以将其抽出来/
方式二 定义一个VO对象
自定义vo文件名 LoginVO java
文件内容
package struts login;
public class LoginVO
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;
在Action文件中 要使用这个vo
文件内容
package struts login;
public class LoginAction
private LoginVO user = null;
public String execute()
System out println (LoginAction class hashCode());
if (user getUsername() equalsIgnoreCase( aaa ) &&
user getPassword() equals( aaaaaa ))
return loginSuc ;
else
return loginFail ;
public LoginVO getUser()
return user;
public void setUser(LoginVO user)
this user = user;
登陆成功的文件如下
<%@ page contentType= text/; charset=gb %>
<%@ taglib uri= /struts tags prefix= s %>
<meta equiv= content type content= text/;charset=gb >
欢迎您 <s:property name= user username >登录成功
注意login文件的部分也要进行修改
文件内容如下
<meta equiv= content type content= text/;charset=gb >
<title>login </title>
<form action= login action method= post >
username:<input type= input name= user username ><br>
password:<input type= input name= user password ><br>
<input type= submit value= 登录 >
cha138/Article/program/Java/hx/201311/26891相关参考