Results 1 to 3 of 3
  1. #1
    raghu9198's Avatar
    raghu9198 is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Question Servlet Error -illegal start of expression

    hello Everybody,
    I have written code to send mail to someone's mailbox

    when I am compiling the code it is displaying 2 errors
    here is my code :

    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.net.*;


    public class Mails extends HttpServlet
    {

    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException, IOException
    {
    printwriter out=response.getwriter();
    response.setcontenttype("text/html");
    {
    String d_email = "immigration@gmail.com";
    String d_password = "mitsproject";
    String d_host = "smtp.gmail.com";
    String d_port = "465";
    String[] m_to={"raghu9198@gmail.com"};
    String m_subject = "Testing";
    String m_text = "Hey, this is the testing email using smtp.gmail.com.";

    public synchronized static boolean sendMail(String userName,String passWord,String host,String port,String starttls,String auth,boolean debug,String socketFactoryClass,String fallback,String[] to,String[] cc,String[] bcc,String subject,String text)
    {
    Properties props = new Properties();
    props.put("mail.smtp.user", userName);
    props.put("mail.smtp.host", host);
    if(!"".equals(port))
    {
    props.put("mail.smtp.port", port);
    }
    if(!"".equals(starttls))
    {
    props.put("mail.smtp.starttls.enable",starttls);
    props.put("mail.smtp.auth", auth);
    }
    if(debug)
    {
    props.put("mail.smtp.debug", "true");
    }
    else
    {
    props.put("mail.smtp.debug", "false");
    }

    if(!"".equals(port))
    {
    props.put("mail.smtp.socketFactory.port", port);
    }
    if(!"".equals(socketFactoryClass))
    {
    props.put("mail.smtp.socketFactory.class",socketFa ctoryClass);
    }

    if(!"".equals(fallback))
    {
    props.put("mail.smtp.socketFactory.fallback", fallback);
    }

    try
    {
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(debug);
    MimeMessage msg = new MimeMessage(session);
    msg.setText(text);
    msg.setSubject(subject);
    msg.setFrom(new InternetAddress("immigrationportal@gmail.com"));
    for(int i=0;i<to.length;i++)
    {
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to[i]));
    }
    for(int i=0;i<cc.length;i++)
    {
    msg.addRecipient(Message.RecipientType.CC, new InternetAddress(cc[i]));
    }
    for(int i=0;i<bcc.length;i++)
    {
    msg.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[i]));
    }
    msg.saveChanges();

    Transport transport = session.getTransport("smtp");

    transport.connect(host, userName, passWord);

    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    return true;
    }
    catch (Exception mex)
    {
    mex.printStackTrace();
    return false;
    }

    }
    }
    }
    }

    And My errors are :
    ---------- compile ----------
    Mails.java:42: illegal start of expression
    public synchronized static boolean sendMail(String userName,String passWord,String host,String port,String starttls,String auth,boolean debug,String socketFactoryClass,String fallback,String[] to,String[] cc,String[] bcc,String subject,String text)
    ^
    Mails.java:117: ';' expected
    }
    ^
    2 errors

    Output completed (2 sec consumed)
    what could be the problem please help me
    Thanks in advance
    Raghu

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Check the code's brackets

    It looks like your doPost() method brackets "{}" are not correct. Please check that the closing bracket is in the correct place.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    rama.katreddy is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    Why do you need a brace here:

    response.setcontenttype("text/html");
    {

    You can keep the sendMail() outside the doPost().
    checkout.....

Similar Threads

  1. Illegal Start of Expression
    By vince425 in forum New To Java
    Replies: 3
    Last Post: 10-18-2008, 07:41 AM
  2. illegal start of expression
    By razmyasdfg in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-27-2008, 10:44 PM
  3. Illegal Start of an Expression
    By David55 in forum CLDC and MIDP
    Replies: 8
    Last Post: 11-02-2007, 09:11 PM
  4. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:09 PM
  5. Illegal Start of an Expression
    By David55 in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-20-2007, 05:59 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
  •