页面:userLogin.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib prefix="s" uri="/struts-tags" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<title>登录成功时登录按钮不再显示(返回同一页面的)</title>
<script src="../scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function hide(){$("#fm_login").hide();}
</script>
</head>
<body id="bd" style="text-align:center;" οnlοad="${login.loginOk}">
<s:form id="fm_login" action="adminLoginAction.action" method="post">
<table id="tb_login" align="right">
<tr>
<td><div id="div_loginName"><s:textfield name="login.loginName" theme="simple">loginName:</s:textfield></div></td>
<td><div id="div_loginPwd"><s:password name="login.password" theme="simple">password:</s:password></div></td>
<td><div id="div_loginSubmit"><s:submit value="login" theme="simple"></s:submit></div></td>
</tr>
</table>
</s:form>
</body>
</html>
---------------------------------------------------------------------------------------------------------------------------
实体bean:LoginBean
public class LoginBean {
private String loginName;
private String password;
private String loginOk;
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getLoginOk() {
return loginOk;
}
public void setLoginOk(String loginOk) {
this.loginOk = loginOk;
}
}
三个属性:用户名和密码的,还一个是当输入正确用户名和密码后要调隐藏函数的(loginOk)
---------------------------------------------------------------------------------------------------------------------------
Action中方法:
/***
* 判断是否是管理员登录(即有上传和删除的权限)
* @return
*/
public String AdminLogin()
{
String l_name = login.getLoginName();
String l_pwd = login.getPassword();
System.out.println("name= "+l_name+" pwd= "+l_pwd);
if(l_name.equals("admin") && l_pwd.equals("admin"))
{
login.setLoginOk("hide()");
//ActionContext.getContext().getSession().put("loginOk", login.getLoginOk());
return "success";
}
else
return "failed";
}
---------------------------------------------------------------------------------------------------------------------------
struts.xml,返回同一页面配置
<!-- 判断是否是管理员的Action -->
<action name="adminLoginAction" class="image_left.ActionImageLeft" method="AdminLogin">
<result name="input">/page/success.jsp</result>
<result name="failed">/page/login.jsp</result>
<result name="success">/page/image_left.jsp</result>
</action>