2 Replies Latest reply: May 15, 2014 10:30 AM by gimbal2 RSS

    servlet Exception

    namrata.jain04

      index.jsp

      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"

          pageEncoding="ISO-8859-1"%>

      <head>

      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

      <title>Insert title here</title>

      </head>

      <body>

      <form action="mail" method="get">

          To:<input type="text" name="to"/><br/>

          Subject:<input type="text" name="subject"><br/>

          Text:<textarea rows="10" cols="70" name="msg"></textarea><br/>

          <input type="submit" value="submit">

          </form>

      </body>

      </html>

       

      Mail.java

      public class Mail extends HttpServlet {

        @Override

          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

              response.setContentType("text/html");

              PrintWriter out = response.getWriter();

       

              String to=request.getParameter("to");

              String subject=request.getParameter("subject");

              String msg=request.getParameter("msg");

              out.println(to);

              out.println(subject);

              Mailer.send(to, subject, msg);

              /*String value=Mailer.getValue();*/

              out.print("message has been sent successfully");

              out.close();   

          }

       

         

      }

      Mailer.java

      public static void send(String to,String subject,String msg){

       

              final String user="namrata.jain04@gmail.com";//change accordingly

              final String pass="xxxxx";

       

              //1st step) Get the session object

              Properties props = new Properties();

              props.setProperty("mail.smtp.host","localhost");

              /*props.put("mail.smtp.host", "smtp.gmail.com");

               props.put("mail.smtp.port", "27");

              props.put("mail.smtp.auth", "true");*/

       

              Session session = Session.getDefaultInstance(props,

               new javax.mail.Authenticator() {

                protected PasswordAuthentication getPasswordAuthentication() {

                 return new PasswordAuthentication(user,pass);

                 }

              });

              //2nd step)compose message

              try {

               MimeMessage message = new MimeMessage(session);

               message.setFrom(new InternetAddress(user));

               message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));

               message.setSubject(subject);

               message.setText(msg);

       

               //3rd step)send message

               Transport.send(message);

       

               System.out.println("Done");

       

               } catch (MessagingException e) {

                  throw new RuntimeException(e);

               }

          

              }

      }

       

       

      i include mail.jar and servlet.jar in my STS

      when i run this exception occur

      exception

      javax.servlet.ServletException: Servlet execution threw an exception 

      root cause

      java.lang.NoClassDefFoundError: javax/mail/MessagingException com.mypack.Mail.doGet(Mail.java:40) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 

      root cause

      java.lang.ClassNotFoundException: javax.mail.MessagingException org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523) com.mypack.Mail.doGet(Mail.java:40) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
        • 1. Re: servlet Exception
          namrata.jain04

          sir please rply me

          • 2. Re: servlet Exception
            gimbal2

            I can't, I don't know what an "STS" is.

             

            I can only make some general observations.

             

            - you never ever need to deploy any kind of servlet.jar; if a server is capable of running servlets, it has all the classes it needs already to be able to do so.

            - the error is clearly about a missing JavaMail class, so whatever you think you are doing right, the deployment of your application is not correct as not all the necessary jars are ending up in the WEB-INF/lib of your application

             

            Its up to you to figure out how to solve your problems, I can't possibly know what buttons you are pushing.