Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:44:57+00:00 2026-06-10T03:44:57+00:00

I have a Java file which has a useful code and I want to

  • 0

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.

Java 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);
        }
    }
}

and my JSP code is:

<html>
<body>
  <jsp:useBean id="link" scope="application" class = "com.me.SSL" />            
  <% out.println("ok"); %>    
</body>
</html>

and tom cat folder config is

webapps\root\web-inf
                   |
                   -classes\com\me\SSL.class
                   |                   
                   -lib\mail.jar
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:44:59+00:00Added an answer on June 10, 2026 at 3:44 am

    You can use

    <jsp:useBean id="link" scope="application" class = "com.me.SSL" />          
    <jsp:setProperty name="link" property="prop" value=""/>
    <% out.println("ok"); %>    
    

    and modify code

    public class SSL {
      String prop;
    
      public String getProp() {
        return prop;
      }
    
      public void setProp(String prop) {
        this.prop = prop;
        main(null);
      }
    
      public static void main(String[] args) {
        Properties props = new Properties();
    

    this means that you call main method when property is set.

    if you were not using jsp:useBean

    <%@ page import="com.me.SSL" %>
    <html>
    <body>
      <% new SSL().main(null); out.println("ok"); %>    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a java ee project which has a text file that uses a
I have a Java project which has this file structure (shown in Eclipse): ProjectName
I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/
I have java source code in a text file. There has to be entered
I have a .jar file which has a command line interface. I want to
I have a big (1.9 GB) XML file which has data I want to
I have problem with my Java program. How I read xml -file which has
I have a .java src file that looks like this: class Test { public
I have a Java application and a build file which, among its tasks, has
Possible Duplicate: Prepend lines to file in Java I have a CSV-file which supports

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.