Why does the Web project click the Register button to jump to the registration page? (Previous blog post)
Since the last registration page was successfully accessed (previous blog), I started writing the registration page. Finally, the user name and password are successfully inserted into the database!
But there's a problem! I login just registered page, the system began to error!!
Nested exception is org.apache.ibatis.exceptions. toomanyresultsexception:expected One result (or null) to being returned by SelectOne (), but found:2 atOrg.mybatis. Spring. Mybatisexceptiontranslator.translateexceptionifpossible (mybatisexceptiontranslator.java:75) at Org.mybatis.spring.sqlsessiontemplate$sqlsessioninterceptor.invoke (sqlsessiontemplate.java:371) at Com.sun.proxy . $Proxy 6.selectOne (Unknown Source)
See the red font I guess it's time to log in from the database to find two user names!
Why do you have two usernames??? To check the database, found that I have just registered the user name is really repeated! (The user name is not a primary key, so it can be unique)
Very doubtful why is two, so I registered a user name, found that the database is also two ....
I do not think that, when I register should only have a user name Ah, inadvertently found that whenever I refresh the page, the database will be more than a duplicate record.
It's hard to understand why this is so!
Later I found the problem, that is, when I completed the registration, jump to the login page, the URL is not changed!!! Because I'm using a forward! The difference between redirection and forwarding is not detailed here.
Here I only explain the URL in the forwarding address bar will not change!!!
So, when I completed the registration jump to the login page, my URL has not changed, is still the URL of the registration page. Plus my request for a GET request, the parameters are all on the URL.
Http://localhost:8080/springmvc_mybatis1110/login.action?usercode=123&password=123
So, whenever I refresh the page, it will invoke the interface of the registration function, the database will be one more data!
Then the problem was found;
Here to solve the problem
The problem is simple, will be redirected to redirect to the login page, the URL will be changed to the URL of the login page, so that the database will not be inexplicable increase data!
Why is the registration page refreshed once, the database has a more data?????