Results 1 to 2 of 2
  1. #1
    tascoa is offline Member
    Join Date
    Oct 2008
    Posts
    16
    Rep Power
    0

    Default jsp authentication

    Hi, I have login JSP:
    XML Code:
    <%
    String username=request.getParameter("username");
    if (username=="tom")
        {
            out.println("YES");
        }
    else
        {
            out.println("NO");
        }
    %>
    and the output in browser, if I enter username tom is NO. Why is this error? I think, that the if statement is right. Thanks a lot for Your ideas. :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Avoid comparing Strings with ==. Instead use either the equals(...) method or equalsIgnoreCase(..).

    For instance,
    Java Code:
    <%
    String username=request.getParameter("username");
    if (username.equalsIgnoreCase("tom"))
        {
            out.println("YES");
        }
    else
        {
            out.println("NO");
        }
    %>

Similar Threads

  1. problem in j_security_check authentication
    By Mrs. Deswal in forum Networking
    Replies: 2
    Last Post: 05-28-2009, 10:26 AM
  2. [SOLVED] How to do authentication
    By Mrs. Deswal in forum Networking
    Replies: 8
    Last Post: 05-21-2009, 02:54 PM
  3. IIS Authentication
    By akkarin in forum Java Applets
    Replies: 0
    Last Post: 03-30-2009, 12:35 PM
  4. Form Based Authentication
    By archmisha in forum Java Servlet
    Replies: 1
    Last Post: 02-06-2009, 11:27 AM
  5. servlet filter authentication
    By pradeepprathyu in forum Advanced Java
    Replies: 0
    Last Post: 11-22-2008, 12:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •