用户登陆界面(非调用数据库)

模拟用户登陆注册的小代码,并无调用数据库,使用APPLICATION实现
 
用户USERBEAN代码
 
package bean;



public class UserBean {

	private String username;

	private String password;

	private String type;

	

	public String getPassword() {

		return password;

	}

	public void setPassword(String password) {

		this.password = password;

	}

	public String getType() {

		return type;

	}

	public void setType(String type) {

		this.type = type;

	}

	public String getUsername() {

		return username;

	}

	public void setUsername(String username) {

		this.username = username;

	}

	

	

}
登陆界面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>



<html>

<form name="SubForm" method="post" action="sub.jsp">

<body>



<div align="center"><h2>用户登陆</h2>

<table>

<tr><td>

用户名<input type="text" name="username"></td>

<td>密码<input type="password" name="password"></td>

</tr><br/>

<tr><td>

管理员<input type="radio" name="type" value="s">普通用户<input type="radio" name="type" value="c" checked>

</td>

</tr>

</table>



</div><br/><br/>

<div align="center"><input type="submit" value="提交">

<input type="reset" value="重置">   <a href="reg.jsp">注册</a></div>





</body>



</form>

</html>
 
注册界面
 
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>

<html>

<body>

<div align="center"><h2>注册页面</h2>

<form name="RegForm" method="post" action="reguser.jsp">

<table>

<tr><td>

用户名<input type="text" name="username"></td><td>

密码<input type="password" name="password"></td>

</tr>

<tr><td>

管理员<input type="radio" name="type" value="s">普通用户<input type="radio" name="type" value="c" checked>

</td></tr>

</table>

<input type="submit" value="提交">

<input type="reset" value="重置">

</form>

</div>

</body>



</html>
 
注册判断JSP
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>



<jsp:directive.page import="bean.UserBean;"/>

<%

ArrayList userlist=(ArrayList)application.getAttribute("userlist");

String username;

String password;

String type;



if(userlist==null||userlist.size()==0){

	userlist=new ArrayList();

			}

	UserBean user=new UserBean();

	username=request.getParameter("username");

	password=request.getParameter("password");

	type=request.getParameter("type");

	user.setUsername(username);

	user.setPassword(password);

	user.setType(type);

	

	userlist.add(user);

	application.setAttribute("userlist",userlist);

%>

<a href="Index.jsp">注册成功 点击跳转</a>
 
 
提交判断JSP代码段
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<jsp:directive.page import="bean.UserBean;" />
<%
 String username=null;
 String password=null;;
 String type=null;;
 String url=null;
 ArrayList userlist = (ArrayList) application
   .getAttribute("userlist");
 if (userlist == null || userlist.size() == 0) {
  url = "登陆错误!";
  %>
  <%=url%>
  <%
  
  return;
  
 }
 username = request.getParameter("username");
 password = request.getParameter("password");
 type = request.getParameter("type");
 for (int i = 0; i < userlist.size(); i++) {
  UserBean user = (UserBean) userlist.get(i);
  if(username.equals(user.getUsername())&&password.equals(user.getPassword())){
   if(type.equals("s")){
    url="管理面界面";
     }
   else{
    url="普通用户界面";
     }
  
     }
  else{
  url="密码错误!";
  }
 }
%>
<%=url%>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值