Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Prob in adding Java Bean in Apache Tomcat/4.0.3

 
mat jacquez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to add an smtp authentication in my contact form using jsp. I have this line in my jsp file --> ( <jsp:useBean id="MyPasswordAuthenticator" class="mypackage.MyPasswordAuthenticator" /> ) After I uploaded the compiled class file and test it in http, I encountered an error. I search for the exception and found this:
"Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated because it is an interface or is an abstract class."
Heres the error and the code for the authentication:
=== error header
javax.servlet.ServletException: class mypackage.MyPasswordAuthenticator : java.lang.InstantiationException: mypackage.MyPasswordAuthenticator
===end error header
==== 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);
}
}
=== end code
I'm just new to java so i have no idea how it could be done. Any ideas? Thanks in advance.
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java beans *MUST* have a no-arg constructor for them to work in JSP, that is in the spec.
HTH
 
mat jacquez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really have no idea how to do it. Anybody who can help me on this. Cause I only copy those codes from a forum too, which is not intended for jsp. I really appreciate it. Thank you very much.
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mat,
You have the following constructor in your class:

You need to remove this constructor and create a method which will do the same task.
HTH
 
mat jacquez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this following code thanks very much!
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;
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!