•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 391,570 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,657 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 854 | Replies: 3
![]() |
•
•
Join Date: Nov 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
to this servlet i have to get values of to,from address and filename from a jsp though all jar files are put in class path the servlet is not recognized
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
String to = request.getParameter("to");
String from = request.getParameter("from");
String host = request.getParameter("host");
String filename = request.getParameter("filename");
//String msgText1 = "Sending a file.\n";
//String subject = "Sending a file";
// create some properties and get the default Session
Properties props = System.getProperties();
// Add property for smtp server.
props.put("mail.smtp.host", host);
Session mailSession =
Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to,false));
msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse
( "vineeth.kumar@bhasin.in", false));
msg.setSubject(
"This message was sent with JavaMail...");
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText("JavaMail... It works! ");
MimeBodyPart mbp2 = new MimeBodyPart();
/** Create the FileDataSource. The constructor requires the fully
qualified path to the file. Note that we use
File.separator to put the correct separator (/,\,:,etc) between
the directory and file name. This way, you can pass in the path
and file_name and your email program doesn't care if it is running
on Unix, Windows or Macintosh.**/
String file_dir = "D:/";
String file_name = filename;
String fs = System.getProperty("file.separator");
FileDataSource fds = new FileDataSource(file_dir+fs+file_name);
// Next, attach the file data source to the MimeBodyPart
mbp2.setDataHandler(new DataHandler(fds));
/** We can use the MimeBodyPart.setFileName() method to set the
name of the attachment as it will appear in the email. Generally,
this is set to the name used to generate the data source (fds.getName()),
although you can set it to any String value. **/
mbp2.setFileName(fds.getName());
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the MimeMessage object msg
msg.setContent(mp);
// use the static Transport method to send the
Transport.send(msg);
System.out.println("Message Sent");
}
catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
String to = request.getParameter("to");
String from = request.getParameter("from");
String host = request.getParameter("host");
String filename = request.getParameter("filename");
//String msgText1 = "Sending a file.\n";
//String subject = "Sending a file";
// create some properties and get the default Session
Properties props = System.getProperties();
// Add property for smtp server.
props.put("mail.smtp.host", host);
Session mailSession =
Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to,false));
msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse
( "vineeth.kumar@bhasin.in", false));
msg.setSubject(
"This message was sent with JavaMail...");
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText("JavaMail... It works! ");
MimeBodyPart mbp2 = new MimeBodyPart();
/** Create the FileDataSource. The constructor requires the fully
qualified path to the file. Note that we use
File.separator to put the correct separator (/,\,:,etc) between
the directory and file name. This way, you can pass in the path
and file_name and your email program doesn't care if it is running
on Unix, Windows or Macintosh.**/
String file_dir = "D:/";
String file_name = filename;
String fs = System.getProperty("file.separator");
FileDataSource fds = new FileDataSource(file_dir+fs+file_name);
// Next, attach the file data source to the MimeBodyPart
mbp2.setDataHandler(new DataHandler(fds));
/** We can use the MimeBodyPart.setFileName() method to set the
name of the attachment as it will appear in the email. Generally,
this is set to the name used to generate the data source (fds.getName()),
although you can set it to any String value. **/
mbp2.setFileName(fds.getName());
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the MimeMessage object msg
msg.setContent(mp);
// use the static Transport method to send the
Transport.send(msg);
System.out.println("Message Sent");
}
catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
}
•
•
Join Date: Nov 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>get</servlet-name>
<servlet-class>get</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>get</servlet-name>
<url-pattern>/get</url-pattern>
</servlet-mapping>
In web.xml this is all what i have what else should i include
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>get</servlet-name>
<servlet-class>get</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>get</servlet-name>
<url-pattern>/get</url-pattern>
</servlet-mapping>
In web.xml this is all what i have what else should i include
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
- Previous Thread: Project
- Next Thread: help in here


Linear Mode