java web 程序--注册页面/HashMap的用法。。要懂啊

思路:1.一个form表单,用户输入后,提交

      2.第二个是注册页面,主要是用Map。先假设往map里面拿东西,然后判断是否为空

    若为空,new 一个HashMap它的子类,然后通过map.containsKey()这个方法判断,用户

  他注册的用户名是否与之相同,若不同则,注册成功,这里把用户输入的name,和pass,通过put()方法

存在map里,让后用setAttribute()把信息存在里面,否则注册失败,那么做一个跳转,重新注册

只做一个注册验证页面,form免了

yan.jsp

 <body>

    <%
    	Map map=(HashMap)session.getAttribute("map");
    	if(map==null){
    		map=new HashMap();
    	}
    	
   
     		String name=request.getParameter("username");
     		String pass=request.getParameter("pass");
     			if(!map.containsKey(name)){
     				out.print("注册成功!");
     				map.put(name,pass);//这里的name和pass已经是字符串了String类型,不需要双引号
     				session.setAttribute("map",map);
     			}else{
     				out.print("您好,该用户名已被注册,请重新注册!");
     				out.print("<a href='zhuce.jsp'>重新注册</a>");
     			}
     
     
      %>
  </body>

  这里要注意的是方法里参数的类型,很重要。不要瞎写

原文地址:https://www.cnblogs.com/langlove/p/3718513.html