E
E
Ethernets2016-03-24 19:50:27
JavaScript
Ethernets, 2016-03-24 19:50:27

Register/Login View Posts Servlet?

Can you tell me how to implement the registration of new subscribers?

There is a DB with the register table and fields login, pass, message, online. The main question is how to check whether a given user exists in the database or not, because now the same login can be created n times, did I read in the open spaces what needs to be processed through js?

How then to bind the servlet to js or do I need to bind jsp to js? or all together? How does this actually happen? Maybe someone has an example? I don't think I'm the only one who will benefit from this post.

Further, I wonder if there is such a user, how to display a tooltip with a message that there is such a user in the database? Then it's interesting how the login works, namely how to remember that the user is logged in. Here I think spring security can handle this issue?

Further, I would like to know how to count users, how many are registered (here I think you can use sql - a query to calculate how many fields in the database or by id), how to determine how many people are currently online?

And, of course, a feedback point, or messages, how to do it similarly to messages on this resource or as in VK, that is, if a message has arrived for a specific user (as I understand it, here we form an sql query to search for a person in the database, and if there is one, then in its message field we put the text after clicking on the send button), how to make it appear immediately without refreshing the page.

Please share your experience, interesting articles, I will be very grateful for any of your advice, and your opinions, help me figure it out, maybe you, as experts, see this implementation differently. Thank you all very much

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sirs, 2016-03-25
@sirs

Advice from me: divide your very voluminous task into several smaller ones. Because you have ten questions in one question at once. Take your technical task / task / project and cut it into small, understandable parts, the smaller, the better. And solve problems gradually, step by step.
The user gets to the login.jsp or index.jsp page, enters his login and password, presses the login/sing in button - you send a post request to the server in your servlet. The servlet calls your UserService, the service should call Dao and fetch the User entity from the database. Further, the credits usually entered by the user are run through md5 or something else and compared with those that were retrieved from the database. If they match, the user either receives rights or is added to a certain list and gets access to other resources. Access rights are usually checked in the Filter when a resource is requested.
If you don’t want to bother with a homemade bike, then yes - see spring-security, there are a lot of materials and examples on it.
What did you mean when you mentioned js ? In a context to collect the data from login form and to make submit on the server? Or are you looking for a way to get data from the database using js?

M
MrBe, 2016-03-28
@MrBe

sirs is right. Break the task down into smaller tasks.
If I understood your problem correctly, then the solution could be as follows.
The user entered the data, pressed the login / sing up button, you sent a POST request to the server. This request will process some specific Action; Service -> Dao -> BD will already be called in it. Design pattern: Front Controller + Strategy ( stackoverflow.com/a/3542297/6099067). In the service, we pull a record from the User table, see if there is one, check the password and redirect it where necessary. If such a user does not exist or the password does not match, then we redirect the user to the same login page but with an error, they say, sorry friend, I don’t have such a user in the database.
In the case when a user wants to register with a login already in the database, there are several options. It is possible that when he presses sing up a request is sent to the server, this request will be processed by some kind of RegistrationAction and he will already decide how and what to do. Options: Action pulls the Service and first asks if there is a user with such a login, if not, then ok -> add it to the database, if so, then redirect the user to the same registration page and send him a message saying sorry this login is already taken. This will all happen when the login/sing up button is clicked..... as soon as he enters a login and switches to another field, then we create a script in JS that, using AJAX technology, will send a request to the server, for example, in CheckLoginAction, which will take the login and check it for entry into the database, if it enters, then we send back the message to the user, they say, such a login is busy, if everything is fine and does not enter, then we don’t send anything. Then this message is displayed when exiting the JS function. JS allows you to edit the page code on the fly.

E
Ethernets, 2016-03-25
@Ethernets

What did you mean when you mentioned js ? In a context to collect the data from login form and to make submit on the server? Or are you looking for a way to get data from the database using js?

Yes, I want when the user entered the login, the data was checked in the database and a message was displayed if such a user already exists, and prohibit registration accordingly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question