Solved

<jsp:setProperty Problem

Posted on 2003-11-20
9
598 Views
Last Modified: 2010-04-01
I'm really stumped on using setProperty for jsp......

This is my initial login page:

<HTML>
<BODY>
<h2>Login</h2>
<FORM METHOD=POST ACTION="Authentication2.jsp">
ID: <INPUT TYPE=TEXT NAME=uid SIZE=20><BR>
Password: <INPUT TYPE=PASSWORD NAME=pw SIZE=20><BR>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
----------------_----------------_----------------_----------------

<jsp:useBean id="auth" class="com.wrox.auth.Authenticate" scope="session"/>
<jsp:setProperty name="auth" property="*"/>
<HTML>
<BODY>
<%
if(auth.checkEntry())
{
     %>
     <A HREF="Logged.jsp">Continue</A>
     <%
}
else
{
     %>
     <A HREF="LoginPage.jsp">Invalid! Continue</A>
     <%
}
%>
</BODY>
</HTML>

----------------_----------------_----------------_--------------------------------_----------------_----------------_----------------


I checked my logs and basically it says that my username and password variables were never initialized....
here's my java code for Authenticate


----------------_----------------_----------------_--------------------------------_----------------_----------------_----------------


package com.wrox.auth;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;


public class Authenticate
{
     String uid;
     String pw;
     String url = "ldap://127.0.0.1:389/";
     String BDN = "o=rcms2";

     public void setUid(String value)
     {
          uid = "uid="+value+", "+BDN;
     }

     public void setPw(String value)
     {
          pw = value;    
     }

     public String getUid()
     {
          return uid;
     }


     public boolean checkEntry()
     {
          Hashtable env = new Hashtable(11);
          env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, url);

          //Authenticate
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          System.out.println("TEST: "+uid);
          env.put(Context.SECURITY_PRINCIPAL, uid);
          env.put(Context.SECURITY_CREDENTIALS, pw);
          try
          {
                   // Create initial context
                   DirContext ctx = new InitialDirContext(env);
                   ctx.close();
          }
          catch (AuthenticationException e1)
          {
               //System.out.println("Invalid Password.");
               return false;
          }
          catch (NamingException e)
          {
                   e.printStackTrace();
          }
          return true;
     }
}



Any pointers? Thanks Sorry my points offering is so low, that's all i have =(.  I jsut know that my problem is that my two variables in my java class (uid and pw).  If i am doing it incorrectly, can someone please show me how to do it properlY? Thanks.
0
Comment
Question by:lapchern
[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
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:jarasa
ID: 9786184
Hi Lapchern.

I'm not really good at Beans but shouldn't you need a constructor on your Bean which would set the value of uid & pw. Well if that was a normal class you should initialize those variable on a constructor like this

public void Authenticate (String myUid, String myPw)
     {
          uid = myUid;
          pw = myPw;
     }

and you should call that constructor with the form, but as I told you I'm not common with Beans so I can assure you that's your problem.

Maybe it will work if you initialize uid & pw at the declaration, like this:

String uid = "";
String pw = "";



Hope it helps anyway.

Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9786203
>>and you should call that constructor with the form, but as I told you I'm not common with Beans so I can assure you that's your problem.

Can't assure you that's your problem, sorry.

Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9786363
Hi again.
I've been reading, ha, yes reading, incredible, I think you must have a constructor but without parameters on your bean and initilize there all the fields of your bean, something like this.

public void Authenticate ()
     {
          uid = null;
          pw = null;
     }

I think That may be the problem.

regards
Javier
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lapchern
ID: 9786644
Hi jarasa, I really appreciate your effort and thanks.

I'm very new at this, but according to this tutorial I've been following at http://www.jsptut.com/Forms.jsp

you do not need a constructor. I verified this by testing the provided sample code myself and it ran perfectly fine. i'm really dumbfounded by my problem... i'm trying to pretty much follow the example of this site...but my variables aren't initialized properly via "set" methods as the site says.
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9786844
Hi again.

I have tryed the code you have here without the LDAP part I just put this:

package com.wrox.auth;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;


public class Authenticate
{
     String uid;
     String pw;
     String url = "ldap://127.0.0.1:389/";
     String BDN = "o=rcms2";

     public void setUid(String value)
     {
          uid = "uid="+value+", "+BDN;
     }

     public void setPw(String value)
     {
          pw = value;    
     }

     public String getUid()
     {
          return uid;
     }


     public boolean checkEntry()
     {
           
      System.out.println(uid);
      System.out.println(pw);
     
      if(user.equals("uid=Javier, o=rcms2"))
                  return true;
      else
                  return false;
                  
/*                  
          Hashtable env = new Hashtable(11);
          env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, url);

          //Authenticate
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          System.out.println("TEST: "+uid);
          env.put(Context.SECURITY_PRINCIPAL, uid);
          env.put(Context.SECURITY_CREDENTIALS, pw);
          try
          {
                   // Create initial context
                   DirContext ctx = new InitialDirContext(env);
                   ctx.close();
          }
          catch (AuthenticationException e1)
          {
               //System.out.println("Invalid Password.");
               return false;
          }
          catch (NamingException e)
          {
                   e.printStackTrace();
          }
          return true;
          */
     }
}


And works fine with Tomcat 4. maybe you should see if you are doing well the LDAP check.

Javier
0
 

Accepted Solution

by:
webhsu earned 25 total points
ID: 9787929
I dont' know, but don't you need a getPw() method also?

To agree with someones' comments above, I've written a lot of these forms and a constructor is not necessary.
0
 

Author Comment

by:lapchern
ID: 9791102
Damn thank yoU!!!!!!!
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9795539
Just Curious.
did you solve your problem, putting the getPw() ??
Javier.
0
 

Author Comment

by:lapchern
ID: 9802008
yeah
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Today’s effective marketing is about coming down to the customers’ level and engaging in a whole new way. A text message is one of the most effective and influential ways that you can engage your customers. Here are eight ways that you can utilize t…
Learn why we support net neutrality and why the topic is important to all internet users.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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