Solved

<jsp:setProperty Problem

Posted on 2003-11-20
9
596 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
Technology Partners: 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
AlarmClock Challenge 35 157
maven j2ee examles 2 64
by zero exception 10 82
spring maven example issues 3 97
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
The goal of this blog is: - To define the incident management process - To go over the key elements of an incident management system - To look into incident alert management tools that integrate with ConnectWise.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 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