Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a Java class in JSP
    text
    copied!<p>I have a Java file which has a useful code and I want to call that Java code in my JSP file. I have tried this, for instance I am using a Java file which successfully sends email to a mail ID. But if I call it in a JSP page its running error free but the email is not sent.</p> <p><strong>Java code:</strong></p> <pre><code>package com.me; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SSL { public static void main(String[] args) { Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("prakash.d2222","**********"); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("from@no-spam.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("prakash_d22@rediffmail.com")); message.setSubject("Testing Subject"); message.setText("Dear Mail Crawler," + "from core java"); Transport.send(message); System.out.println("Doneit"); } catch (MessagingException e) { throw new RuntimeException(e); } } } </code></pre> <p><strong>and my JSP code is:</strong></p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;jsp:useBean id="link" scope="application" class = "com.me.SSL" /&gt; &lt;% out.println("ok"); %&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and tom cat folder config is</p> <pre><code>webapps\root\web-inf | -classes\com\me\SSL.class | -lib\mail.jar </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload