Registration and login implementation under JavaBean - Web development

This article mainly creates a login and registration interface. The user needs to register first. The registered content is stored in JavaBean. Then, after entering the account and password on the login page, the data stored in JavaBean is called up for comparison. If the account and password are correct, the jump is Next page, return if incorrect. The background here is to enter an idiom solitaire game page.

This is actually an assignment. After I finish it, I thought I would post it and save it. If it can help you in some way, that would be great~ I am a newbie and the page is not that good. You can understand the logic. Oh( ̄y▽, ̄)╭ 

ps: The code in this article is implemented in eclipse .

Registration interface-register.jsp

<%@ page contentType="text/html" %>
<%@ page pageEncoding = "utf-8" %> 
<HTML><body bgcolor = #FFE4B5>
<style>
   #ts{
   font-family:宋体; font-size:19; color:black
   }
</style>
<form action="">
<br>用户注册 </br>
<br>设置账号: <input type=text id=ts name="name" size=15/> </br>
<br>设置密码: <input type=text id= ts name="password" size=15/> </br>
<br><input type="submit" id="ts" value="注册" /> </br>
</form>
<% String aa=request.getParameter("name");
if (aa==null||aa.length()==0)
{
    return;
}
else{%>
<jsp:useBean id="user" class="tom.bean.User" scope="session"></jsp:useBean>
<jsp:setProperty property="*" name="user"/>
用户<jsp:getProperty property="name" name="user"/>注册成功!
<br>三秒后跳转至登录页面
<meta http-equiv="refresh" content="3;url=login.jsp">
<%} %>
</body></HTML>

Login interface-login.jsp

<%@ page contentType="text/html" %>
<%@ page pageEncoding = "utf-8" %> 
<HTML><body bgcolor = #f0c2a2>
<style>
   #ts{
   font-family:宋体; font-size:19; color:black
   }
</style>
<form action="">
<br>用户登录 </br>
<br>账号:  <input type=text id=ts name="name" size=15/> </br>
<br>密码:  <input type=text id= ts name="password" size=15/> </br>
<br><input type="submit" id="ts" value="登录" /> </br>
</form>
<% String aa=request.getParameter("name");
if (aa==null||aa.length()==0)
{
	return;
}
else{%>
<jsp:useBean id="user" class="tom.bean.User" scope="session"></jsp:useBean>
<% String Name=request.getParameter("name");
   String Password=request.getParameter("password");
   String name=user.getName(); //useBean后,设置的id就是一个对象,可以通过id.xxx进行对JavaBean里的函数的调用
   String password=user.getPassword();
   if(Name.equals(name)==false)
   {
	   out.print("账号有误,请重新输入!");
	   return;
   }
   else if(Password.equals(password)==false)
   {
	   out.print("密码有误,请重新输入!");
	   return;
   }
   else{%>
<br>登录成功!即将跳转至游戏界面...
<meta http-equiv="refresh" content="3;url=inputIdioms.jsp">
<%} %>
<%} %>
</body></HTML>

Here, only the account text box is used to determine whether the login interface is empty. Logically speaking, both the account and password text boxes should be judged at the same time. Here, because there is not enough time, only one is judged. In a real situation It must be judged by two people together!

JavaBean-User.java

package tom.bean;

public class User 
{
    String name;
    String password;
    public void setName(String name)
    {
        this.name=name;
    }
    public String getPassword() 
    {
        return password;
    }
    public void setPassword(String password) 
    {
        this.password = password;
    }
    public String getName() 
    {
        return name;
    }

}


 

Game page-inputIdioms.jsp ( I put it here so that you can test the success of the code. This is just a boring idiom solitaire game that requires you to enter it yourself~)

<%@ page contentType="text/html" %>
<%@ page pageEncoding = "utf-8" %>
<jsp:useBean id="idioms" class="sea.water.ContinueIdioms" scope="application" />
<style>
   #tomStyle{
      font-family:宋体;font-size:26;color:blue 
   }
</style>
<% request.setCharacterEncoding("utf-8");
%>
<jsp:setProperty name="idioms" property="nowIdioms" param ="nowIdioms" />
<HTML><body bgcolor = #a2d2e2>
<p id = tomStyle>
目前的接龙情景:<br>
<textArea id = tomStyle rows=5 cols=38>
<%= idioms.getAllIdioms() %>
</textArea><br>
<form  action="" id = tomStyle method = post >
继续接龙,输入成语:<text  name="nowIdioms" value = 10 />
<br><input type="text" name ="nowIdioms"  id = tomStyle />
<input type="submit"  id = tomStyle value="提交"/>
</form> 
</p></body></HTML>


 

JavaBean-ContinueIdioms.java of the game page

package sea.water;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class ContinueIdioms {
    LinkedList<String> listIdioms ;//存放成语的链表。
    public String nowIdioms;      //当前参与接龙的成语。
    public ContinueIdioms(){
        listIdioms = new LinkedList<String>();
    }
    public synchronized void setNowIdioms(String s){
        nowIdioms = s;
        try{
           String previous = listIdioms.getLast(); //得到上次添加的成语。
           //上一个成语的最后一个字符:
           char endChar = previous.charAt(previous.length()-1);
           char startChar = nowIdioms.charAt(0);//当前成语的第一个字符。
           if(startChar == endChar) 
                  listIdioms.add(nowIdioms);
         }
         catch(NoSuchElementException exp){
            listIdioms.add(nowIdioms);
            System.out.println(exp);
         }
    }
    public String getAllIdioms(){
        StringBuffer buffer = new StringBuffer();
        Iterator<String> iterator =listIdioms.iterator();
        if(iterator.hasNext() == false)
           buffer.append("→");
        while(iterator.hasNext()){
           buffer.append(iterator.next()+"→");
        }
        return new String(buffer);
    }
}


 

The following is the interface diagram after the code is run - they are: registration, login and game interface (I think the most important part is the implementation of registration and login)

Anyway that’s it! I think the code still has room for major upgrades, so I’ll continue studying it after I finish my class in the afternoon! This upgrade is also left to you in front of the screen. I hope this article can help you and stimulate more ideas in you!

Afternoon! ヾ(•ω•`)o

Guess you like

Origin blog.csdn.net/m0_53101456/article/details/127361459