Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-01-2009, 12:49 PM
raghu9198's Avatar
Member
 
Join Date: Dec 2008
Posts: 32
Rep Power: 0
raghu9198 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-01-2009, 04:41 PM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,159
Rep Power: 3
CJSLMAN is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-22-2009, 12:12 AM
Member
 
Join Date: Apr 2009
Posts: 4
Rep Power: 0
rama.katreddy is on a distinguished road
Default
Why do you need a brace here:

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

You can keep the sendMail() outside the doPost().
checkout.....
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Illegal Start of Expression vince425 New To Java 3 10-18-2008 08:41 AM
illegal start of expression razmyasdfg CLDC and MIDP 2 07-27-2008 11:44 PM
Illegal Start of an Expression David55 CLDC and MIDP 8 11-02-2007 10:11 PM
Illegal start of expression gabriel New To Java 2 08-01-2007 06:09 PM
Illegal Start of an Expression David55 CLDC and MIDP 0 04-20-2007 06:59 AM


All times are GMT +2. The time now is 03:00 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org