dcsimg
I call a javamail class from a jsp and works but don't work if i call it from a function
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Antonio_Fonseca
Posted On:   Thursday, August 21, 2003 08:31 AM

I have a javamailbean class, that works ok if i call it from a jsp, but i try to call it from a function, and even if don't return any error, nothing happens. This is the code I use to try classes, the next lines of code, retunrs nothing...... ******************************* public static void main(String[] args) { System.out.println( "Runing"); String result = mail.JavaMailBean.send("from@*.*","to@*.*","cc@*.*","bcc@*.*","Subject","Message","smtpserver"); } ********************** But if I put it in a jsp like this, it will send the email ! </>    More>>

I have a javamailbean class, that works ok if i call it from a jsp, but i try to call it from a function, and even if don't return any error, nothing happens.


This is the code I use to try classes, the next lines of code, retunrs nothing......
*******************************

			


public static void main(String[] args) {
System.out.println( "Runing");


String result = mail.JavaMailBean.send("from@*.*","to@*.*","cc@*.*","bcc@*.*","Subject","Message","smtpserver");
}

**********************
But if I put it in a jsp like this, it will send the email !
			


</>


String result = mail.JavaMailBean.send("from@*.*","to@*.*","cc@*.*","bcc@*.*","Subject","Message","smtpserver");

************

Sorry, but i'm new in java, so i'm probably missing something, cano You help me please?

Best Regards
Antonio Fonseca    <<Less

Re: I call a javamail class from a jsp and works but don't work if i call it from a function

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, August 21, 2003 11:43 AM

You are doing a jsp:useBean but then you are not directly referencing it anywhere (e.g. you don't appear to be referencing the new page scope bean you created, named "sendMail").


Perhaps it (the new "sendMail" mail.JavaMailBean object, created by the jsp:useBean) is silently setting things up, that need to be set up, e.g. connection, session etc., in order for your static method "mail.JavaMailBean.send" to work? perhaps you need to get a new mail.JavaMailBean object, in the standalone version (e.g. doing the same thing that the "jsp:useBean" does), before the call to your static method "mail.JavaMailBean.send"? or rewrite things so that initialization is either more explicit e.g. move it out of the constructor, or is implicit in that your "send" method might check and if initialization hasn't been done yet, it will do it itself first (create the necessary object, and call initialization methods, assuming you move them out of the constructor itself)?


Also it seems questionable to me, design clarity wise, for you to have to create a new object first, to implicitly get things initialized, but from then on only use static class methods, not calling methods on the new object itself, apparently "ignoring" the new object (even though it apparently is doing essential work for you in the background, to make your static methods work)?

About | Sitemap | Contact