Solved

Help creating a Login servlet

Posted on 2003-11-23
4
636 Views
Last Modified: 2013-11-24
This is a chunk of my code from my LoginServlet.java:

      public void printLoginTable(PrintWriter out)

      {
            

            out.println("<h2>Login</h2>");
            out.println("<FORM METHOD=POST ACTION="/com/wrox/servlet/Authenticate1">");
            out.println("ID: <INPUT TYPE=TEXT NAME=uid SIZE=20><BR>");
            out.println("Password: <INPUT TYPE=PASSWORD NAME=pw SIZE=20><BR>");
            out.println("<P><INPUT TYPE=SUBMIT>");
            out.println("</FORM>");
              String userId = req.getParameter("uid");
              String password = req.getParameter("pw");
                bool validated = validate(userId,password);
                if(validated)
                 {
                           printLogged(out);
                 }
                 else
                 {
                          out.println("INVALID");
                          //then go back to some other page...
                 }
      }

basically its purpose is to create the HTML form to take in a user id and password, then the last two lines are supposed to take those two parameters and process those strings elsewhere. Am i doing this correctly?  I'm guessing not because i have to worry about the "onclick" action of an html form...but how do i make my req.getParameter wait for onclick? Or am i totally off?
0
Comment
Question by:jinduy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 9805687
Your main problem is a logical one. What you're doing is simultaneously creating a form to allow the user to log in and behaving as if a login has already taken place. If you are only just creating the form, how can

>>String userId = req.getParameter("uid");

be anything other than null, unless the login *has* taken place? And if it has, why print the login form?

What you should be doing is either using two different pages - one to print the form and another to receive it, or, if you're using the same page/servlet, you should be either printing the form or processing it, but not both.

You should really save the login in the session, so if you can't find it in the session, you know the user has to log in and you can print the login form.


0
 

Expert Comment

by:lapchern
ID: 9808658
oh yeah... userID will always be null =(


can you please elaborate more on saving the "login in the session..."

how do i save the login in a session? Do u mean saving the username of the login in the session? Thanks
0
 

Author Comment

by:jinduy
ID: 9808664
oops i replied with my lab partner's login just now...so yeah...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9810090
>>Do u mean saving the username of the login in the session?

Yes.

requestion.getSession().setAttribute("username", username);
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question