Hello.

I have such a problem: there are two fields for authorization, there is a button. How in JSP read the values ​​of these fields in some kind of variable (to write to the session).

I would not like through request.getParameter , because then the login and password are displayed in the string. If there is any standard version, then please offer.

Thank you in advance.

  • There is a type of request to the server as POST. Use it. On the server in any way, except as a request, do not send data. - Anton Mukhin
  • post request, in a servlet or elsewhere - take data from request and write to session. - Viacheslav

3 answers 3

 String password = request.getParameter("password"); 

What is the problem then?


Reply to comments

Why do you have an input field first and then a form?

That would not have a password in the browser line, use POST

Something like this:

 <form action="" method="POST"> <input type="password" name="password"> <input type="submit" value="Log In"> </form> <% if(request.getParameter("password") == null){ if(request.getParameter("password").equals("")) { out.println("<html><font color=red>Введи пароль мудила</font></html>"); } else { String password= request.getParameter( "password" ); session.setAttribute( "password", password ); } } %> 
  • The fact is that I don’t want to include the password field in the "Form" Password: <input type = "password" name = "password"> <form action = "Page2.jsp" method = "get"> <input type = "submit" value = "Log In"> </ form> so that on the next page the password is not displayed in the address bar. In general, I need either to pry out the password on the same page and shove it into the session, or on the next page, but so that the password can not be seen anywhere. - zaitcbkru
  • LTD! Beauty is beautiful. Everything is working. Thank you, kind man! - zaitcbkru

But it's not easier just to put in the form where the password TYPE is PASSWORD, then when entering you will have asterisks, and not the entered characters? Or am I misunderstanding something?

  • It is clear that you can put the type of the password field, I do not know how then to pull the value out of this field into a variable of type String. - zaitcbkru
  • @deeplulz browsers substitute passwords in this field if the user chose to remember ... which is not always desirable. - Vadim

Hello

The first! NEVER WRITE LOGIC IN JSP !!!! 11 For this purpose, there are at least servlets, which can be sent a request, and even better Spring MVC + Spring Security will help solve the authorization problem.

Writing logic in JSP is almost criminal.

The second.

 public class ServletDemo extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{ // здесь можно поучить любую инфу, вызвать нужные сервсисы и т.д. } } 

And about authorization you can see here - The Java EE 5 Tutorial