The Artima Developer Community
Sponsored Link

Java Answers Forum
problem with my java class

6 replies on 1 page. Most recent reply: Sep 14, 2003 9:39 PM by mat jacquez

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
mat jacquez

Posts: 4
Nickname: c2mejacq
Registered: Sep, 2003

problem with my java class Posted: Sep 13, 2003 11:23 PM
Reply to this message Reply
Advertisement
I have a problem converting my class having constructor to a plain method. Cause java beans doesn't like constructor. I got error. Can anybody help me on this? Thanks in advance. This is my code;

package mypackage;

import javax.mail.*;

public class MyPasswordAuthenticator extends Authenticator
{
String user;
String pw;
public MyPasswordAuthenticator (String username, String password)
{
super();
this.user = username;
this.pw = password;
}
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(user, pw);
}
}

------------- here is the contructor part-----------------

public MyPasswordAuthenticator (String username, String password)
{ super();
this.user = username;
this.pw = password;
}

-------------------------------------------------------


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: problem with my java class Posted: Sep 14, 2003 4:39 AM
Reply to this message Reply
Why don't you use a static initializer and call supper() in that?

By the way what is the error you are getting?

mat jacquez

Posts: 4
Nickname: c2mejacq
Registered: Sep, 2003

Re: problem with my java class Posted: Sep 14, 2003 7:31 AM
Reply to this message Reply
I don't know how, cause if I use super i also have an error during compiling the java file. Sorry, i'm just a new student of java. I will be using the code to authenticate my contactpage (html) to smtp. Please help.

This is the error.
javax.servlet.ServletException: class mypackage.MyPasswordAuthenticator : java.lang.InstantiationException: mypackage.MyPasswordAuthenticator

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: problem with my java class Posted: Sep 14, 2003 7:45 AM
Reply to this message Reply
Why dont you have a empty constructor and then have another method which takes user name and password?
public MyPasswordAuthenticator () 
{ 
super(); 
} 


And have getters and setters for username and password?

mat jacquez

Posts: 4
Nickname: c2mejacq
Registered: Sep, 2003

Re: problem with my java class Posted: Sep 14, 2003 2:01 PM
Reply to this message Reply
I didn't get it. What i know from other forum ,is this ->> 'Java beans *MUST* have a no-arg constructor for them to work in JSP, that is in the spec'.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: problem with my java class Posted: Sep 14, 2003 6:22 PM
Reply to this message Reply
That's what I am trying to tell here.

Instead of
public MyPasswordAuthenticator (String username, String password) 
{ 
super(); 
this.user = username; 
this.pw = password; 
} 
public PasswordAuthentication getPasswordAuthentication() 
{ 
return new PasswordAuthentication(user, pw); 
} 


why don't you try this
public MyPasswordAuthenticator (){
   super(); 
}
public void setUsername(String username){
   this.username = username;
}
public String getUsername(){
   return this.username;
}
public void setPassword(String password){
   this.password = password;
}
public String getPassword(){
   return this.password;
}

mat jacquez

Posts: 4
Nickname: c2mejacq
Registered: Sep, 2003

Re: problem with my java class Posted: Sep 14, 2003 9:39 PM
Reply to this message Reply
Thank you very much Senthoorkumaran Punniamoorthy, I'll try it tommorrow when i have the java, cause right now its not installed in this computer. I hope everythings okay. Again thank you for the help.

Flat View: This topic has 6 replies on 1 page
Topic: is it possible to use struts-bean taglib for internationalisation Previous Topic   Next Topic Topic: share global hash map across multiple threads

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use