Results 1 to 2 of 2
  1. #1
    gb.rashu is offline Member
    Join Date
    Aug 2010
    Posts
    28
    Rep Power
    0

    Question how to solve errors?

    Hello all,
    I am writing code for sending email through JSP.
    I am getting error .. cau you tell me how to solve this error.

    here is code:(sendmail.jsp)
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>

    <table border="1" width="50%" cellpadding="0" cellspacing="0">
    <tr>
    <td width="100%">
    <form method="POST" action="sendemail.jsp">
    <table border="1" width="100%" cellpadding="0" cellspacing="0">
    <h1>Mail API</h1>
    <tr>
    <td width="50%"><b>To:</b></td>
    <td width="50%"><input type="text" name="to" size="30"></td>
    </tr>
    <tr>
    <td width="50%"><b>From:</b></td>
    <td width="50%"><input type="text" name="from" size="30"></td>
    </tr>
    <tr>
    <td width="50%"><b>Subject:</b></td>
    <td width="50%"><input type="text" name="subject" size="30"></td>
    </tr>
    <tr>
    <td width="50%"><b>Description:</b></td>
    <td width="50%"><textarea name="body" type="text"
    cols="40" rows="15" size=100>
    </textarea>
    </td>
    </tr>
    <tr>
    <td><p><input type="submit" value="Send Mail" name="sendMail"></td>
    </tr>
    </table>

    </form>
    </td>
    </tr>
    </body>
    </html>

    ///sendemail.jsp////


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <%@ page import="java.util.*" %>
    <%@ page import="javax.mail.*" %>
    <%@ page import="javax.mail.internet.*" %>
    <%@ page import="javax.activation.*" %>
    <%
    String host = "localhost";
    String to = request.getParameter("to");
    String from = request.getParameter("from");
    String subject = request.getParameter("subject");
    String messageText = request.getParameter("body");
    boolean sessionDebug = false;
    // Create some properties and get the default Session.
    Properties props = System.getProperties();
    props.put("mail.host", host);
    props.put("mail.transport.protocol", "smtp");
    Session mailSession = Session.getDefaultInstance(props, null);

    // Set debug on the Session
    // Passing false will not echo debug info, and passing True will.

    mailSession.setDebug(sessionDebug);

    // Instantiate a new MimeMessage and fill it with the
    // required information.

    Message msg = new MimeMessage(mailSession);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    msg.setText(messageText);

    // Hand the message to the default transport service
    // for delivery.

    Transport.send(msg);
    out.println("Mail was sent to " + to);
    out.println(" from " + from);
    out.println(" using host " + host + ".");
    %>
    </table>
    </body>
    </html>


    ///errors //


    HTTP Status 500 -

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Unable to compile class for JSP:

    An error occurred at line: 32 in the jsp file: /sendemail.jsp
    Session cannot be resolved to a type
    29: Properties props = System.getProperties();
    30: props.put("mail.host", host);
    31: props.put("mail.transport.protocol", "smtp");
    32: Session mailSession = Session.getDefaultInstance(props, null);
    33:
    34: // Set debug on the Session
    35: // Passing false will not echo debug info, and passing True will.


    An error occurred at line: 32 in the jsp file: /sendemail.jsp
    Session cannot be resolved
    29: Properties props = System.getProperties();
    30: props.put("mail.host", host);
    31: props.put("mail.transport.protocol", "smtp");
    32: Session mailSession = Session.getDefaultInstance(props, null);
    33:
    34: // Set debug on the Session
    35: // Passing false will not echo debug info, and passing True will.


    An error occurred at line: 42 in the jsp file: /sendemail.jsp
    Message cannot be resolved to a type
    39: // Instantiate a new MimeMessage and fill it with the
    40: // required information.
    41:
    42: Message msg = new MimeMessage(mailSession);
    43: msg.setFrom(new InternetAddress(from));
    44: InternetAddress[] address = {new InternetAddress(to)};
    45: msg.setRecipients(Message.RecipientType.TO, address);


    An error occurred at line: 42 in the jsp file: /sendemail.jsp
    MimeMessage cannot be resolved to a type
    39: // Instantiate a new MimeMessage and fill it with the
    40: // required information.
    41:
    42: Message msg = new MimeMessage(mailSession);
    43: msg.setFrom(new InternetAddress(from));
    44: InternetAddress[] address = {new InternetAddress(to)};
    45: msg.setRecipients(Message.RecipientType.TO, address);


    An error occurred at line: 43 in the jsp file: /sendemail.jsp
    InternetAddress cannot be resolved to a type
    40: // required information.
    41:
    42: Message msg = new MimeMessage(mailSession);
    43: msg.setFrom(new InternetAddress(from));
    44: InternetAddress[] address = {new InternetAddress(to)};
    45: msg.setRecipients(Message.RecipientType.TO, address);
    46: msg.setSubject(subject);


    An error occurred at line: 44 in the jsp file: /sendemail.jsp
    InternetAddress cannot be resolved to a type
    41:
    42: Message msg = new MimeMessage(mailSession);
    43: msg.setFrom(new InternetAddress(from));
    44: InternetAddress[] address = {new InternetAddress(to)};
    45: msg.setRecipients(Message.RecipientType.TO, address);
    46: msg.setSubject(subject);
    47: msg.setSentDate(new Date());


    An error occurred at line: 45 in the jsp file: /sendemail.jsp
    Message.RecipientType.TO cannot be resolved to a type
    42: Message msg = new MimeMessage(mailSession);
    43: msg.setFrom(new InternetAddress(from));
    44: InternetAddress[] address = {new InternetAddress(to)};
    45: msg.setRecipients(Message.RecipientType.TO, address);
    46: msg.setSubject(subject);
    47: msg.setSentDate(new Date());
    48: msg.setText(messageText);


    An error occurred at line: 53 in the jsp file: /sendemail.jsp
    Transport cannot be resolved
    50: // Hand the message to the default transport service
    51: // for delivery.
    52:
    53: Transport.send(msg);
    54: out.println("Mail was sent to " + to);
    55: out.println(" from " + from);
    56: out.println(" using host " + host + ".");


    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:423)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:308)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:286)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:273)
    org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)

    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
    Apache Tomcat/6.0.14


    Thanks in advance
    ragards
    Rashmi

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    ...and again!

    This should be in a Servlet not a JSP.
    That way you'd catch simple compilation errors long before you deployed to a server.
    But beyond that, this does not belong in a JSP page!

Similar Threads

  1. Please help me solve them
    By quangtrung89 in forum New To Java
    Replies: 2
    Last Post: 11-26-2009, 10:08 PM
  2. How can I solve this errors with files?
    By myskynim in forum Advanced Java
    Replies: 5
    Last Post: 11-20-2009, 09:01 AM
  3. Replies: 3
    Last Post: 03-08-2009, 01:51 AM
  4. Plz solve this....
    By theone3nu in forum Java 2D
    Replies: 3
    Last Post: 01-08-2009, 05:01 PM
  5. Plz solve this....
    By theone3nu in forum New To Java
    Replies: 9
    Last Post: 12-23-2008, 09:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •