How to integrate the following program in a JSP page

I have this JavaMail program that sends emails. It runs from the command prompt. But I want to use it in a jsp page to send emails. But I am very new to JSP and dont know how to do it. Can anyone help me with it??
It will be very helpful if someone gives the JSP code to send emails.
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class msgmultisendsample {
public static void main(String[] args) {
if (args.length != 6) {
System.out.println("usage: java msgmultisend <to> <from> <smtp> true|false <message body 1> <message body 2>");
return;
String to = args[0];
String from = args[1];
String host = args[2];
String msgText1 = args[4];
String msgText2 = args[5];
boolean debug = Boolean.valueOf(args[3]).booleanValue();
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host);
Session session = Session.getInstance(props, null);
session.setDebug(debug);
try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Trial Message from Braps.com");
msg.setSentDate(new Date());
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// Use setText(text, charset), to show it off !
mbp2.setText(msgText2, "us-ascii");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
// send the message
Transport.send(msg);
} catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}

1) Design a Struts JSP page with TO, FROM, HOST, TEXT1, TEXT2 (3 text boxes and 2 textarea) and two buttons for SEND & RESET.
2) Create a ActionForm Class and generate getters & setters for the above form elements
3) Create ActionClass & define the action forward
4) Do action mapping in struts-config.xml file
5) Run and see whether you can able to open JSP page
5) Create one more action class. This is to send email when you hit SEND button. Here only you're going to put your current code you have now.
6) Do one more action mapping in struts-config.xml file, this time the forward page may a confirmation page saying that "Mail has been sent to <the TO id>.
7) You're done.

Similar Messages

  • How to get the view tree from a jsp page

    Hi,
    I would like to get the view tree of a jsp page. The idea is to dynamically include the content of one or more jsf pages into a UIPanel during a "value changed" event.
    So, i could get from an arbitrary page like ...
    <%@ taglib uri="http://java.sun.com/jsf/core"   prefix="f" %>
    <%@ taglib uri="http://java.sun.com/jsf/html"   prefix="h" %>
    <h:panelGrid columns="3" width="100%" rowClasses="gridTop">
        <h:outputText value="#{someBean.someValue}"/>
    </h:panelGrid>... the corresponding List of components...
    Any idea?

    Thanks for your answer Jayashri,
    The view tree can be retrieved by this way during the page is parsed, for example with scriptlets <%%>, or once the page has been parsed (the view has been builded and attached to the FacesContext).
    My problem is to get the view tree of a page from another Context.
    The idea is to build a dynamic layout of some pages that represents "views". I can imagine this like the concept of perspectives and views of Eclipse IDE.
    Because of the difficulty to build it with pure JSP (cannot use dynamic ID nor JSTL ForEach), I try to build it into my backing bean and to bind it with a <h:panelGrid/>. By this way, I'm not able to use the <jsp:include/> tag as I usually did to include some content into the view tree.
    Sorry for my english ;)
    - Renaud.

  • How to suppress the HTTPS alert in a JSP page?

    Hi,
    I have a JSP page which is https,
    If I try to move from that page to another https site or refresh the same page ,
    I am getting the security alert ,
    How to suppress that alert
    Please help me out,
    It is more urgent ....

    I think it is possible because i have seen some sites in the internet which is https but I didnt see any alert for that
    Please help me out

  • How to retrieve the parameter names from a JSP page ? Urgent Please

    Hello,
    Can anybody tell me how to retrieve the parameter names from the JSP
    page. (without using getParameterNames() method.)
    The problem with the getParameterNames() method is I get the Jumbled output.
    I need it very badly
    With regards
    Ananth R
    email:[email protected]
    [email protected]

    Dear duffymo,
    My primary intention is to convert the JSP form information into a XML file.
    If I do not get the Parameter names in the correct order how can I maintain
    tag order in XML file.
    For ex: (JSP PAGE VIEW)
    Name--
    FirstName
    MiddleName
    LastName
    Address--
    Street1
    Street2
    City
    Country
    &so on
    (XML File to be generated)
    <Name>
    <FirstName>Value</FirstName>
    </Name>
    <Address>
    <street1>value</street1>
    </Address>
    & so on
    If I use getParameterNames() to get all the parameter names(Which form the tag names in the XML file ) the Enumeration object it returns will not be in the same order as the text fields in JSP.From this I can not construct a meaningful XML file.
    order means: Order of entry on the page, from top to bottom
    That's it
    Waiting for your responses

  • How to get the current date using HTMLB JSP page

    Hi All, I developed an iview with several fields using PDK, I would like to know how can I include for a date field a dynamic value witch in this case is the current date.
    <hbj:inputField
    id="Date"
    type="date"
    maxlength="10"
    showHelp="TRUE"
    required="TRUE"
    value="???"
    />
    Thanks in advance
    Alexis

    Hi Alexis ,
    u can use the setDate("3.12.2003") function to set date for this input field.
    u just change the id = Date , because in jave we have Date class. rename it to another name..
    suppose id = systemDate
    <%
    Format formater = new SimpleDateFormat("dd.MM.yyyy");
    Date syDatum = new Date();
    %>
    then
    put
        systemDate.setDate(formater.format(syDatum));
    this will set the date .....
                        Regards
                        Kishor Gopinathan

  • How to Access the Remote Servlet through a JSP Page

    Hi ,
    I wrote a servlet in my local system and It is running very well in my tomcat server5.5. Now I write a JSP code an another one system. Now I don't know how to call my servlet when Click a submit button. I need a small example or idea about this. Help me
    Thanks in advance,
    Maheshwaran Devaraj

    Just like any other servlet or form-processing script. What would a mere HTML page know about "systems"? Put the URL into the form destination attribute and be done.

  • How to stop the Browser from caching my web pages

    Hi There
    Can anyone tell how to stop the browser from caching my jsp pages
    I am using
    <%response.setHeader("Cache-Control","no-cache");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);
    %>
    but this does not work anduser is able to go back to the previous page
    which i dont want and i want the browser to display the message the page has expired
    Help appreciated
    Thanks
    Mumtaz

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("max-age", 0);
    response.setDateHeader("Expires", 0);
    I have cut paste the code from my jsp which is working. There is one additional line. I do not know if that is the cause but there is no harm in trying that out.
    Srinivasan Ranganathan

  • How to call the form bean value on jsp withthe help of jstl tag

    hi
    all friends
    i am working in struts & i use jstl tag in jsp. i have one problem rise is how to call the form bean value in jsp page by using jstl tag.
    i now how to retrive the value through jsp:logic
    eg. <logic:empty name="userListForm" property="users">
    NO USER FOUND
    </logic:empty>
    see * userListForm mean formbaen name.
    * users means collection object.
    so how can i write above e.g in jstl

    You use the jstl core:if or core:choose combined with the EL:
    <c:if test="${empty users.userListForm}">
    NO USERS FOUND
    </c:if>I suggest you lookup the jsp expression language (EL) using google, it's very powerful.

  • When I open firefox, a pop up window asks "do you want to allow the following program to make changes to this computer? How can I get rid of this pop-up window ?

    Every time I open the browser, a pop-up window asks "Do you want the following program to make changes to this computer?"
    It is unnecessary and annoying to have to click "yes" each time.
    How can I get this pop-up window to stop?

    Thanks for the help I'll keep the info just in case - but I got so frustrated that I just deleted the program and then re downloaded the current version now everything works fine.

  • How do I get rid of 'Do you want to allow the following program..."?

    I have recently installed Windows 7 on a new computer and have also installed Dreamweaver MX.
    Whenever I open Dreamweaver, it comes up with an annoying message "Do you want to allow the following program to make changes to this computer?"
    My question is this - how can I get Windows 7 to recognise Dreamweaver MX so that this message does NOT come up anymore?
    Or do I have to upgrade my Dreamweaver to the latest version (probably quite expensive).
    To see a screenshot of a similar message, see this thread:
    http://www.sevenforums.com/general-discussion/14310-how-get-rid-do-you-want-allow.html
    Thank you

    chuckee wrote:
    Or do I have to upgrade my Dreamweaver to the latest version (probably quite expensive).
    Thank you
    As Murray stated, it's been about 8 years.  Adobe only allows you to upgrade from the previous 3 versions.  Right now they are on CS5 (11) which means you can upgrade from Dreamweaver 8 which is 2 versions after yours.  So you would have to buy the full version again.  Buying the upgrade is no longer an option.

  • How do I get rid of "do you want to allow the following program to make changes to this computer"?

    I recently installed Adobe Acrobat 8 Professional and every time I open a PDF file that is stored on my computer, I get a pop-up that asks "Do you want to allow the following program to make changes to this computer?".  How do I get rid of this?  I don't want to change my security settings, I just want to open pdf's without having to go through this step.
    I'm using Windows 7.

    Thanks for that good idea.  I checked the "properties" by right clicking on the AA8 icon and under "compatability" I noticed it had Windows XP (Service Pack 3).  Since I'm running Windows 7, I changed it to that and now I don't get that annoying pop-up!

  • How do I rid the User Account Control - "Do you want the following program to make changes to this computer?" - FireFox Helper pop-up that shows after every log in?

    The following pop-up is displayed after every log-in, even after it is clicked yes after previous log-ins. Several students log-in the computers daily. How do I rid THIS?:
    User Account Control
    "Do you want the following program to make changes to this computer?
    Program Name: FireFox Helper
    Verified Publisher: Mozilla Corporation
    File Origin: Hard Drive on this Computer

    In Windows 7, Microsoft updated UAC in several ways. By default, UAC does not prompt when certain programs included with Windows make changes requiring elevated permissions. Other programs still trigger a UAC prompt. The strictness of UAC can be changed to either always prompt, or to never do so.
    [http://windows.microsoft.com/eN-US/windows-vista/What-is-User-Account-Control What is User Account Control?]
    [http://windows.microsoft.com/en-US/windows-vista/Turn-User-Account-Control-on-or-off Turn User Account Control on or off]
    It is the same on win7.
    [http://en.wikipedia.org/wiki/User_Account_Control User Account Control]
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • Says please close the following programs to continue. listed is toolbar. How do I close "toolbar"

    says please close the following programs to continue. listed is toolbar. How do I close &quot;toolbar&quot; to get the program to proceed?
    There is no IE open either

    See How to close Internet Explorer and other programs running on Windows?

  • How to I get rid of pop up user account control "do you want to allow the following program to make changes to your computer" I have windows 7 professional.

    I keep getting an annoying pop up the says "User Account Control" "Do you want to allow the following program to make changes to your computer"
    == This happened ==
    Every time Firefox opened
    == Two days after I downloaded Firefox and set as my default browser.

    Check that you do not run Firefox as Administrator.
    Right-click the Firefox desktop shortcut and choose "Properties".
    In the Compatibility tab, make sure that Privilege Level: "Run this program as Administrator" is not selected.
    You also need to check the Properties of the firefox.exe program in the Firefox program directory.
    If you can't make the changes then you need to start Windows Explorer as Administrator.

  • How to include the ordinary program in the BOR object type program

    Hi Guys, while i am trying to include a program in the BOR object type program. It is showing the following error:
    "Statement 'INCLUDE Z_ERC_SEARCH_VALOFACT_MACRO .' is not permitted in BOR".
    then, i tried to add  "<" and ">" to enclose it, but it wants the access key to create it.   anyone knows how to add the ordinary program in the BOR object type program.

    It's correct that we CAN'T insert our INCLUDES in BOR program. We CAN only use TYPE-POOLS there. So you can create Type Group with TYPES, CONSTANTS and DEFINE statements, and then use them in BOR programs.
    Using DEFINE you can construct MACROs with parameters and call your code there. It's limited, and not the easiest way, but some things can be achieved this way. Also forget about using Code Patterns while editing Type Group.
    Note: Use TYPE-POOLS statement after INCLUDE statement in BOR program .
    Best regards,
    Tomas.

Maybe you are looking for

  • Can't figure this out: locating a MBP on the same wifi network

    Can't figure this out: when my 13" MBP is connected wirelessly to my Airport base station, my iPad can see it. When I connect the MBP to the base station via ethernet cable (for faster connection), the iPad can no longer see it. Note: my airport is n

  • OC4J help

    Hi all I am using jdev 10.1.2, my project run fine in embedded OC4J. But when i deploy to standalone OC4J i get the error : JBO-30003: The application pool (emart.model.services.EmartServicesLocal) failed to checkout an application module due to the

  • Queued delta, unserialised v3 update, direct delta

    Can you any body tell what are the advantages between queued and other(Un serilised, direct) deltas.

  • IPad Photo Sync never ends....

    Hi there, I tried syncing a folder containing several thousand photos a while ago and then cancelled the sync without letting it finish. Since then I cannot sync any photos onto my iPad, even folders containing only a few photos. The itunes sync just

  • Developing Portlets

    I have some info in an XML DB. I need a quick and dirty demo or sample code of how to extract data from that XML database via a Portlet and through Soap, OC4J web services. Any Thoughts? Please Help.