This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General forum!

vikassheel gupta

Ranch Hand
+ Follow
since Aug 02, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by vikassheel gupta

Hi
ya i know that in application server we use servlets and jsp's but for start i just want to run a simple application so that i can check out the debugging process and can see how to run a simple application on this weblogic

thanks if u pls help me in solving this issue...
14 years ago
Hi I am new in weblogic as i tried to run a java simple application on weblogic but i am facing a simple problem that the start option is disable..

the steps i did for that is

1. create weblogic application 2. create weblogic project then in WEB-INF>src create a java class

public class test {
public static void main(String as[]) {
System.out.println("Hello World 1");
System.out.println("Hello World 2");
System.out.println("Hello World 3");
System.out.println("Hello World 4");
}
}


after that i build the application but when i try to debug the project or debug the java file then start button is disable so can any one tell me how to run this simple application in weblogic

Thanks & Warm Regards
Vikas Sheel Gupta
9911005168
vikassheelgupta@rediffmail.com
14 years ago
Hi I am new in weblogic as i tried to run a java simple application on weblogic but i am facing a simple problem that the start option is disable..

the steps i did for that is

1. create weblogic application 2. create weblogic project then in WEB-INF>src create a java class

public class test {
public static void main(String as[]) {
System.out.println("Hello World 1");
System.out.println("Hello World 2");
System.out.println("Hello World 3");
System.out.println("Hello World 4");
}
}


after that i build the application but when i try to debug the project or debug the java file then start button is disable so can any one tell me how to run this simple application in weblogic

Thanks & Warm Regards
Vikas Sheel Gupta
9911005168
vikassheelgupta@rediffmail.com
14 years ago
i am sending an email the mail is sent successfully as a sting .In string i write the whole HTML code and that works fine but one thing here to be noted down is i have to send a image and that image is in data base as in blob data and a java file reterieve that image and print it in socket .
i am using the struts for mapping to that path
so when ever i try to write
String strItem +="<img src=request.getContextPath()/show.do?id=1234>" >;
when i do in this way then my the control doesnt go to that file instead of that simple string in which html text and a blank image is sent
so tell me the solution
so that i can send image and text through my mail
Here is my mail code:-- Bold text is to map the struts-config file and write the image to the socket
******************************************************************************

/*
* Created on Aug 17, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.gpi.h2.web.ecards;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Properties;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import com.gpi.h2.transferobject.CatalougeItem;
import com.gpi.h2.transferobject.EcardsInfo;
import com.gpi.h2.transferobject.UserInfo;
import com.gpi.h2.businessdelegate.ecards.EcardsListImpl;
import com.gpi.h2.web.ecards.SendEcardForm;


/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SendEcardMailAction extends Action
{

private static final String SMTP_HOST_NAME = "192.168.0.250";
private static final String SMTP_AUTH_USER = "tarund";
private static final String SMTP_AUTH_PWD = "password";
private String emailMsgTxt = "";
public String emailSubjectTxt = "";
public String emailFromAddress = "";
// private String filename="c:/two.jpg";
ServletOutputStream out= null;

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
{
try
{
String userid=((UserInfo)request.getSession().getAttribute("UserInfo")).getM_strUserId();

boolean success=false;
HttpSession session = request.getSession(false);
String strItem=null;
String strItemId=null;
String strRecipients=null;
boolean save_image=false;

SendEcardForm ecardform= (SendEcardForm)form;
CatalougeItem l_CatalougeItem= new CatalougeItem();
EcardsListImpl l_EcardListImpl= new EcardsListImpl();
EcardsInfo l_EcardInfo= new EcardsInfo();

String itemid=request.getParameter("id");
l_EcardInfo.setCard_bgcolor(ecardform.getCard_bgcolor());
l_EcardInfo.setFilename(ecardform.getFilename());
l_EcardInfo.setCard_fontColor(ecardform.getCard_fontColor());
l_EcardInfo.setCard_fontSize(ecardform.getCard_fontSize());
l_EcardInfo.setCard_fontface(ecardform.getCard_fontface());
l_EcardInfo.setUserID(ecardform.getUserID());
l_EcardInfo.setCatagoryid(ecardform.getCatagoryid());
l_EcardInfo.setUserID(userid);


String[] astrRecipients;

String forsave=ecardform.getForSave();
if(forsave!=null)
{
save_image=l_EcardListImpl.saveECardLayout(l_EcardInfo);
}
strRecipients=ecardform.getRec_email();
astrRecipients=strRecipients.split(",");



//strItem=filename;
emailSubjectTxt=ecardform.getSubject();
//*****************************************HTML TEXT**************************************

strItem ="<html><body>";
strItem +="<table border=1 align='center' bgcolor='"+ecardform.getCard_bgcolor()+"'>";
strItem +="<tr><td align=left >";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=""+ecardform.getCard_title()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td>";
strItem +="<img src=\http://localhost:8080/Harmonization/ShowEcard.do?id="+itemid+" >";
strItem +="</tr></td>";
strItem +="<tr><td align='center'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getMessage()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td align='right'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getSignature()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="</table>";
strItem +="</body></html>";

//************************************************* End of HTML TEXT*****************



emailMsgTxt=strItem;
System.out.println(emailMsgTxt);
emailFromAddress=ecardform.getSen_email();

if (strRecipients!=null && strRecipients.length()>0)
{
SendEcardMailAction smtpMailSender=new SendEcardMailAction();
smtpMailSender.postMailTo( astrRecipients, emailSubjectTxt, emailMsgTxt, emailFromAddress);
success=true;
}

}catch(Exception e)
{
request.setAttribute("message"," Sorry ..Your mail has not been sent to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentfailure");
return mapping.findForward("error");
}

request.setAttribute("message","You have successfully mail the item to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentsuccess");

return mapping.findForward("ecards.confirmation");

}
public void postMailTo( String[] recipients, String subject, String message , String from) throws MessagingException
{
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();
System.out.println(auth);
Session session = Session.getInstance(props, auth);

session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

//InternetAddress addressTo= new InternetAddress(recipient);
Address[] addressTo=new Address[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);

//********************** code for attachment************************

MimeMultipart mp= new MimeMultipart();

MimeBodyPart attach = new MimeBodyPart();

attach = new MimeBodyPart();
attach.setContent(message,"text/html");
mp.addBodyPart(attach);


msg.setContent(mp);

//**********************end of attachment code***************************

//msg.setContent(message, "text/html");
Transport transport = session.getTransport("smtp");
transport.connect( "192.168.0.250", SMTP_AUTH_USER, SMTP_AUTH_PWD);

transport.sendMessage(msg, msg.getRecipients( Message.RecipientType.TO));
//Transport.send(msg);

}

/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
System.out.println("PasswordAuthentication");
return new PasswordAuthentication(username, password);
}
}

}
i am sending an email the mail is sent successfully as a sting .In string i write the whole HTML code and that works fine but one thing here to be noted down is i have to send a image and that image is in data base as in blob data and a java file reterieve that image and print it in socket .
i am using the struts for mapping to that path
so when ever i try to write
String strItem +="<img src=request.getContextPath()/show.do?id=1234>" >;
when i do in this way then my the control doesnt go to that file instead of that simple string in which html text and a blank image is sent
so tell me the solution
so that i can send image and text through my mail
Here is my mail code:-- Bold text is to map the struts-config file and write the image to the socket
******************************************************************************

/*
* Created on Aug 17, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.gpi.h2.web.ecards;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Properties;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import com.gpi.h2.transferobject.CatalougeItem;
import com.gpi.h2.transferobject.EcardsInfo;
import com.gpi.h2.transferobject.UserInfo;
import com.gpi.h2.businessdelegate.ecards.EcardsListImpl;
import com.gpi.h2.web.ecards.SendEcardForm;


/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SendEcardMailAction extends Action
{

private static final String SMTP_HOST_NAME = "192.168.0.250";
private static final String SMTP_AUTH_USER = "tarund";
private static final String SMTP_AUTH_PWD = "password";
private String emailMsgTxt = "";
public String emailSubjectTxt = "";
public String emailFromAddress = "";
// private String filename="c:/two.jpg";
ServletOutputStream out= null;

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
{
try
{
String userid=((UserInfo)request.getSession().getAttribute("UserInfo")).getM_strUserId();

boolean success=false;
HttpSession session = request.getSession(false);
String strItem=null;
String strItemId=null;
String strRecipients=null;
boolean save_image=false;

SendEcardForm ecardform= (SendEcardForm)form;
CatalougeItem l_CatalougeItem= new CatalougeItem();
EcardsListImpl l_EcardListImpl= new EcardsListImpl();
EcardsInfo l_EcardInfo= new EcardsInfo();

String itemid=request.getParameter("id");
l_EcardInfo.setCard_bgcolor(ecardform.getCard_bgcolor());
l_EcardInfo.setFilename(ecardform.getFilename());
l_EcardInfo.setCard_fontColor(ecardform.getCard_fontColor());
l_EcardInfo.setCard_fontSize(ecardform.getCard_fontSize());
l_EcardInfo.setCard_fontface(ecardform.getCard_fontface());
l_EcardInfo.setUserID(ecardform.getUserID());
l_EcardInfo.setCatagoryid(ecardform.getCatagoryid());
l_EcardInfo.setUserID(userid);


String[] astrRecipients;

String forsave=ecardform.getForSave();
if(forsave!=null)
{
save_image=l_EcardListImpl.saveECardLayout(l_EcardInfo);
}
strRecipients=ecardform.getRec_email();
astrRecipients=strRecipients.split(",");



//strItem=filename;
emailSubjectTxt=ecardform.getSubject();
//*****************************************HTML TEXT**************************************

strItem ="<html><body>";
strItem +="<table border=1 align='center' bgcolor='"+ecardform.getCard_bgcolor()+"'>";
strItem +="<tr><td align=left >";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=""+ecardform.getCard_title()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td>";
strItem +="<img src=\http://localhost:8080/Harmonization/ShowEcard.do?id="+itemid+" >";
strItem +="</tr></td>";
strItem +="<tr><td align='center'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getMessage()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td align='right'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getSignature()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="</table>";
strItem +="</body></html>";

//************************************************* End of HTML TEXT*****************



emailMsgTxt=strItem;
System.out.println(emailMsgTxt);
emailFromAddress=ecardform.getSen_email();

if (strRecipients!=null && strRecipients.length()>0)
{
SendEcardMailAction smtpMailSender=new SendEcardMailAction();
smtpMailSender.postMailTo( astrRecipients, emailSubjectTxt, emailMsgTxt, emailFromAddress);
success=true;
}

}catch(Exception e)
{
request.setAttribute("message"," Sorry ..Your mail has not been sent to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentfailure");
return mapping.findForward("error");
}

request.setAttribute("message","You have successfully mail the item to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentsuccess");

return mapping.findForward("ecards.confirmation");

}
public void postMailTo( String[] recipients, String subject, String message , String from) throws MessagingException
{
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();
System.out.println(auth);
Session session = Session.getInstance(props, auth);

session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

//InternetAddress addressTo= new InternetAddress(recipient);
Address[] addressTo=new Address[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);

//********************** code for attachment************************

MimeMultipart mp= new MimeMultipart();

MimeBodyPart attach = new MimeBodyPart();

attach = new MimeBodyPart();
attach.setContent(message,"text/html");
mp.addBodyPart(attach);


msg.setContent(mp);

//**********************end of attachment code***************************

//msg.setContent(message, "text/html");
Transport transport = session.getTransport("smtp");
transport.connect( "192.168.0.250", SMTP_AUTH_USER, SMTP_AUTH_PWD);

transport.sendMessage(msg, msg.getRecipients( Message.RecipientType.TO));
//Transport.send(msg);

}

/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
System.out.println("PasswordAuthentication");
return new PasswordAuthentication(username, password);
}
}

}
15 years ago
JSF
i am sending an email the mail is sent successfully as a sting .In string i write the whole HTML code and that works fine but one thing here to be noted down is i have to send a image and that image is in data base as in blob data and a java file reterieve that image and print it in socket .
i am using the struts for mapping to that path
so when ever i try to write
String strItem +="<img src=request.getContextPath()/show.do?id=1234>" >;
when i do in this way then my the control doesnt go to that file instead of that simple string in which html text and a blank image is sent
so tell me the solution
so that i can send image and text through my mail
Here is my mail code:-- Bold text is to map the struts-config file and write the image to the socket
******************************************************************************

/*
* Created on Aug 17, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.gpi.h2.web.ecards;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Properties;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import com.gpi.h2.transferobject.CatalougeItem;
import com.gpi.h2.transferobject.EcardsInfo;
import com.gpi.h2.transferobject.UserInfo;
import com.gpi.h2.businessdelegate.ecards.EcardsListImpl;
import com.gpi.h2.web.ecards.SendEcardForm;


/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SendEcardMailAction extends Action
{

private static final String SMTP_HOST_NAME = "192.168.0.250";
private static final String SMTP_AUTH_USER = "tarund";
private static final String SMTP_AUTH_PWD = "password";
private String emailMsgTxt = "";
public String emailSubjectTxt = "";
public String emailFromAddress = "";
// private String filename="c:/two.jpg";
ServletOutputStream out= null;

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
{
try
{
String userid=((UserInfo)request.getSession().getAttribute("UserInfo")).getM_strUserId();

boolean success=false;
HttpSession session = request.getSession(false);
String strItem=null;
String strItemId=null;
String strRecipients=null;
boolean save_image=false;

SendEcardForm ecardform= (SendEcardForm)form;
CatalougeItem l_CatalougeItem= new CatalougeItem();
EcardsListImpl l_EcardListImpl= new EcardsListImpl();
EcardsInfo l_EcardInfo= new EcardsInfo();

String itemid=request.getParameter("id");
l_EcardInfo.setCard_bgcolor(ecardform.getCard_bgcolor());
l_EcardInfo.setFilename(ecardform.getFilename());
l_EcardInfo.setCard_fontColor(ecardform.getCard_fontColor());
l_EcardInfo.setCard_fontSize(ecardform.getCard_fontSize());
l_EcardInfo.setCard_fontface(ecardform.getCard_fontface());
l_EcardInfo.setUserID(ecardform.getUserID());
l_EcardInfo.setCatagoryid(ecardform.getCatagoryid());
l_EcardInfo.setUserID(userid);


String[] astrRecipients;

String forsave=ecardform.getForSave();
if(forsave!=null)
{
save_image=l_EcardListImpl.saveECardLayout(l_EcardInfo);
}
strRecipients=ecardform.getRec_email();
astrRecipients=strRecipients.split(",");



//strItem=filename;
emailSubjectTxt=ecardform.getSubject();
//*****************************************HTML TEXT**************************************

strItem ="<html><body>";
strItem +="<table border=1 align='center' bgcolor='"+ecardform.getCard_bgcolor()+"'>";
strItem +="<tr><td align=left >";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=""+ecardform.getCard_title()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td>";
strItem +="<img src=\http://localhost:8080/Harmonization/ShowEcard.do?id="+itemid+" >";
strItem +="</tr></td>";
strItem +="<tr><td align='center'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getMessage()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td align='right'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getSignature()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="</table>";
strItem +="</body></html>";

//************************************************* End of HTML TEXT*****************



emailMsgTxt=strItem;
System.out.println(emailMsgTxt);
emailFromAddress=ecardform.getSen_email();

if (strRecipients!=null && strRecipients.length()>0)
{
SendEcardMailAction smtpMailSender=new SendEcardMailAction();
smtpMailSender.postMailTo( astrRecipients, emailSubjectTxt, emailMsgTxt, emailFromAddress);
success=true;
}

}catch(Exception e)
{
request.setAttribute("message"," Sorry ..Your mail has not been sent to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentfailure");
return mapping.findForward("error");
}

request.setAttribute("message","You have successfully mail the item to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentsuccess");

return mapping.findForward("ecards.confirmation");

}
public void postMailTo( String[] recipients, String subject, String message , String from) throws MessagingException
{
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();
System.out.println(auth);
Session session = Session.getInstance(props, auth);

session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

//InternetAddress addressTo= new InternetAddress(recipient);
Address[] addressTo=new Address[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);

//********************** code for attachment************************

MimeMultipart mp= new MimeMultipart();

MimeBodyPart attach = new MimeBodyPart();

attach = new MimeBodyPart();
attach.setContent(message,"text/html");
mp.addBodyPart(attach);


msg.setContent(mp);

//**********************end of attachment code***************************

//msg.setContent(message, "text/html");
Transport transport = session.getTransport("smtp");
transport.connect( "192.168.0.250", SMTP_AUTH_USER, SMTP_AUTH_PWD);

transport.sendMessage(msg, msg.getRecipients( Message.RecipientType.TO));
//Transport.send(msg);

}

/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
System.out.println("PasswordAuthentication");
return new PasswordAuthentication(username, password);
}
}

}
15 years ago
i am sending an email the mail is sent successfully as a sting .In string i write the whole HTML code and that works fine but one thing here to be noted down is i have to send a image and that image is in data base as in blob data and a java file reterieve that image and print it in socket .
i am using the struts for mapping to that path
so when ever i try to write
String strItem +="<img src=request.getContextPath()/show.do?id=1234>" >;
when i do in this way then my the control doesnt go to that file instead of that simple string in which html text and a blank image is sent
so tell me the solution
so that i can send image and text through my mail
Here is my mail code:-- Bold text is to map the struts-config file and write the image to the socket
******************************************************************************

/*
* Created on Aug 17, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.gpi.h2.web.ecards;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Properties;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import com.gpi.h2.transferobject.CatalougeItem;
import com.gpi.h2.transferobject.EcardsInfo;
import com.gpi.h2.transferobject.UserInfo;
import com.gpi.h2.businessdelegate.ecards.EcardsListImpl;
import com.gpi.h2.web.ecards.SendEcardForm;


/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class SendEcardMailAction extends Action
{

private static final String SMTP_HOST_NAME = "192.168.0.250";
private static final String SMTP_AUTH_USER = "tarund";
private static final String SMTP_AUTH_PWD = "password";
private String emailMsgTxt = "";
public String emailSubjectTxt = "";
public String emailFromAddress = "";
// private String filename="c:/two.jpg";
ServletOutputStream out= null;

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
{
try
{
String userid=((UserInfo)request.getSession().getAttribute("UserInfo")).getM_strUserId();

boolean success=false;
HttpSession session = request.getSession(false);
String strItem=null;
String strItemId=null;
String strRecipients=null;
boolean save_image=false;

SendEcardForm ecardform= (SendEcardForm)form;
CatalougeItem l_CatalougeItem= new CatalougeItem();
EcardsListImpl l_EcardListImpl= new EcardsListImpl();
EcardsInfo l_EcardInfo= new EcardsInfo();

String itemid=request.getParameter("id");
l_EcardInfo.setCard_bgcolor(ecardform.getCard_bgcolor());
l_EcardInfo.setFilename(ecardform.getFilename());
l_EcardInfo.setCard_fontColor(ecardform.getCard_fontColor());
l_EcardInfo.setCard_fontSize(ecardform.getCard_fontSize());
l_EcardInfo.setCard_fontface(ecardform.getCard_fontface());
l_EcardInfo.setUserID(ecardform.getUserID());
l_EcardInfo.setCatagoryid(ecardform.getCatagoryid());
l_EcardInfo.setUserID(userid);


String[] astrRecipients;

String forsave=ecardform.getForSave();
if(forsave!=null)
{
save_image=l_EcardListImpl.saveECardLayout(l_EcardInfo);
}
strRecipients=ecardform.getRec_email();
astrRecipients=strRecipients.split(",");



//strItem=filename;
emailSubjectTxt=ecardform.getSubject();
//*****************************************HTML TEXT**************************************

strItem ="<html><body>";
strItem +="<table border=1 align='center' bgcolor='"+ecardform.getCard_bgcolor()+"'>";
strItem +="<tr><td align=left >";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=""+ecardform.getCard_title()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td>";
strItem +="<img src=\http://localhost:8080/Harmonization/ShowEcard.do?id="+itemid+" >";
strItem +="</tr></td>";
strItem +="<tr><td align='center'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getMessage()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="<tr><td align='right'>";
strItem +="<font face="+ecardform.getCard_fontface()+" size="+ecardform.getCard_fontSize()+" color="+ecardform.getCard_fontColor()+">";
strItem +=" "+ecardform.getSignature()+" ";
strItem +="</font>";
strItem +="</tr></td>";
strItem +="</table>";
strItem +="</body></html>";

//************************************************* End of HTML TEXT*****************



emailMsgTxt=strItem;
System.out.println(emailMsgTxt);
emailFromAddress=ecardform.getSen_email();

if (strRecipients!=null && strRecipients.length()>0)
{
SendEcardMailAction smtpMailSender=new SendEcardMailAction();
smtpMailSender.postMailTo( astrRecipients, emailSubjectTxt, emailMsgTxt, emailFromAddress);
success=true;
}

}catch(Exception e)
{
request.setAttribute("message"," Sorry ..Your mail has not been sent to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentfailure");
return mapping.findForward("error");
}

request.setAttribute("message","You have successfully mail the item to your friend(s)");
request.setAttribute("towhichlinkforward","/mailsentsuccess");

return mapping.findForward("ecards.confirmation");

}
public void postMailTo( String[] recipients, String subject, String message , String from) throws MessagingException
{
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();
System.out.println(auth);
Session session = Session.getInstance(props, auth);

session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

//InternetAddress addressTo= new InternetAddress(recipient);
Address[] addressTo=new Address[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);

//********************** code for attachment************************

MimeMultipart mp= new MimeMultipart();

MimeBodyPart attach = new MimeBodyPart();

attach = new MimeBodyPart();
attach.setContent(message,"text/html");
mp.addBodyPart(attach);


msg.setContent(mp);

//**********************end of attachment code***************************

//msg.setContent(message, "text/html");
Transport transport = session.getTransport("smtp");
transport.connect( "192.168.0.250", SMTP_AUTH_USER, SMTP_AUTH_PWD);

transport.sendMessage(msg, msg.getRecipients( Message.RecipientType.TO));
//Transport.send(msg);

}

/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
System.out.println("PasswordAuthentication");
return new PasswordAuthentication(username, password);
}
}

}
15 years ago
JSP
hi
i have a problem reated to image retrieval what i did till now i have a column in data base with blob data type
I can easily upload the image with the help of FormFile and BinaryStream but when i try to retrieve that image i face some sort of problem My problem is:--

I got the image in the resultset with the help of connection but its return type is InputStream which doesnt have the write method so that i can not write that image in the jsp page

if i didnt use InputStream and i use byte array and then try to print it again it will not print with no error so i cant not understand why this problem occurs
thanks alot
15 years ago
JSF
Hi dear
i think u dont know the architecture of EJB thats why u ask this thing we use these two interfaces because
home interface cant interact with the beans it will return the bean object
remoter interface doesnt make the object it will interact with the bean through that object which is generated by the home interface so thats why we need these two interfaces

i hope u got this thing
hi
i have a problem reated to image retrieval what i did till now i have a column in data base with blob data type
I can easily upload the image with the help of FormFile and BinaryStream but when i try to retrieve that image i face some sort of problem My problem is:--

I got the image in the resultset with the help of connection but its return type is InputStream which doesnt have the write method so that i can not write that image in the jsp page

if i didnt use InputStream and i use byte array and then try to print it again it will not print with no error so i cant not understand why this problem occurs
thanks alot
Hi dear
i had worked with EJB 2.0 and jdeveloper so
in that case i tell u to make a connection from the data base and choose the EJB from table and then make a bean
now the JNDI in that case wil be ur bean name fine
i think this will help u
bye
hi
the value comes from the prev page is fine it is "9-sep-2000" but when we try to change it or we can say we try to parse it , it shows the parsing error so tell me how can i
or leave all that just tell me ur code how will you convert a string into java.util.Date
thanks alot
15 years ago
hi
In java script u have to use the ascii value in between 48- 57
so on the basis of that u can do that
byeeeeeeeee
enjoy
15 years ago
Here the string is like request.getParameter("text1"); instead of request.getParameter("1-sep-2000")
thanks
15 years ago
Hi
i have a problem related to string conversion in java.util.Date data type so that it can be inserted into the data base so for this telll me how

what i did till now is:---

String adate="";
java.util.Date a_date=null;

SimpleDateFormat ts= new SimpleDateFormat("dd-MMM-yyyy");
adate=request.getParameter("1-sep-2000");
try{
if((adate!=null)&& (!(adate.equals(""))))
{
a_date = (java.util.Date) ts.parse(adate);
}
}catch(ParseException e) {
System.out.println("Unable to parse " + e);
}

out.println("a_date:--"+a_date+"<br>");

but when i run this code the out put will be :--

java.text.ParseException: Unparseable date: "null"
at java.text.DateFormat.parse(DateFormat.java:334)
at jsp_servlet.__dod._jspService(dod.jsp:164)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:971)

but as u can see the value in string is not null but it can not parse that value so tell me the solution
thanks alot for your kind help
15 years ago