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 7940161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:18:25+00:00 2026-06-03T23:18:25+00:00

I have the following doPost in my servlet that inserts a record into the

  • 0

I have the following doPost in my servlet that inserts a record into the postgres db and then sends an email to the user about the purchase. I tested the insert and it works perfectly but when I try to add the code for the send email an exception error happens and I don’t understand why.

I even tested the send email function in a standard a lone java application and it works fine. Heres my code

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Start");
        HttpSession s = request.getSession(true);
        String firstName = (String) s.getAttribute("firstName");
        String lastName = (String) s.getAttribute("lastName");
        String email = (String) s.getAttribute("email");
        String creditCard = (String) s.getAttribute("cCard");

        if (s.getAttribute("bookingCart") != null) {
            System.out.println(firstName);
            if(firstName == null || lastName == null || email == null || creditCard == null) {
                response.sendRedirect("MasterController?confirmBooking=true&error=Data+not+valid");
                return;
            }
            bookingDTO booking = (bookingDTO) s.getAttribute("bookingCart");
            bookingsDAO bookingsDAO = new JDBCBookingsDAO();
            bookingsDAO.confirmPaymentBooking(booking.getId() , email, firstName, lastName, creditCard);
            System.out.println("Booking updated");
            String msg = "Dear Customer,\n Thnk you for Using Our website \n Please use link below to confirm your Booking\n"+
                         " ";
             // Recipient's email ID needs to be mentioned.
              String to = "brice2nic3@gmail.com";

              // Sender's email ID needs to be mentioned
              String from = "brice2nic3@gmail.com";

              // Assuming you are sending email from localhost
              String host = "smtp";

              System.out.println("Proterpies");
              // Get system properties
              Properties properties = System.getProperties();
              System.out.println("Booking updated1");
              // Setup mail server
              properties.setProperty("mail.smtp.host", host);
              System.out.println("Booking updated2");
              // Get the default Session object.
              Session session = Session.getDefaultInstance(properties);
              System.out.println("Booking updated3");
              try{
                  System.out.println("Booking updated4");
                 // Create a default MimeMessage object.
                 MimeMessage message = new MimeMessage(session);
                 System.out.println("Booking updated5");
                 // Set From: header field of the header.
                 message.setFrom(new InternetAddress(from));
                 System.out.println("Booking updated6");
                 // Set To: header field of the header.
                 message.addRecipient(Message.RecipientType.TO,
                                          new InternetAddress(to));
                 System.out.println("Booking updated7");
                 // Set Subject: header field
                 message.setSubject("This is the Subject Line!");
                 System.out.println("Booking updated8");
                 // Now set the actual message
                 message.setText("This is actual message");
                 System.out.println("Booking updated9");
                 // Send message
                 Transport.send(message);
                 System.out.println("Sent message successfully....");
              }catch (MessagingException mex) {
                 mex.printStackTrace();
              }
            s.removeAttribute("bookingCart");
            s.setAttribute("bookingCart", null);
            s.removeAttribute("bookingAmount");
            s.setAttribute("bookingAmount", null);
        } else {
            System.out.println("Booking not updated");
            response.sendRedirect("MasterController?retHome=true");
            return;
        }
        System.out.println("redirected to masterController");
        response.sendRedirect("MasterController?Message=Booking+Successful");
    }

and my exception message is:

java.lang.NoClassDefFoundError: javax/mail/MessagingException
    java.lang.Class.getDeclaredConstructors0(Native Method)

any help would be much appreciated.

  • 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-03T23:18:27+00:00Added an answer on June 3, 2026 at 11:18 pm

    Reason of NoClassDefFoundError is that a particular class is not available in Classpath. Third party API
    mail.jar should be under /WEB-INF/lib under your web application

    You might be running your program using jar command and class was not defined in manifest file’s ClassPath attribute

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code [in doPost()] to edit existing record. It does not
I have servlet that does the following: public class LoginServlet extends HttpServlet { protected
I have the following servlet code public void doPost(HttpServletRequest request, HttpServletResponse response){ Backup bup
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record
I have following script that executes all the .reg files in the current directory.
Using Servlet, I can do the following to process binary stream: public void doPost(HttpServletRequest
I have the following test: test should get create do sign_in(FactoryGirl.create(:user)) assert_difference('Inquery.count') do post
I have the following permissions: create_note, email, offline_access, photo_upload, publish_stream, read_stream, share_item, status_update, manage_notifications,
Using Rails 3.0.3. I have the following route in routes.rb: match user/create_new_password/:reset_password_key =>users#create_new_password, :via=>[:get,
I have the following Java class: package web; import javax.servlet.*; import javax.servlet.http.*; import java.io.*;

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.