Trying to read in redered HTML from a jsp

How can I read in the HTML thats rendered from my jsp to a string buffer so I can dump in a mail function below?
I was thinking I can do :
StringBuffer sb = new StringBuffer();
sb.append
but I dont know exactly how to read in the file to set to the buffer
public void sendMailWithAttachment(String toAddress, String fromAddress, String subject, String msgBody, String attachmentContent, String sFileExt){
        try{
            String hostDNSName  = "mercury.homes.com";
            //String emailBodyContent = null;
            //String subject      = null;
            //Get system properties
            Properties props = System.getProperties();
            //Setup mail server
            props.put("mail.smtp.host", hostDNSName);
            //Get session
            Session session = Session.getDefaultInstance(props, null);
            //Define message
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(fromAddress));
            message.addRecipient(Message.RecipientType.TO,  new InternetAddress(toAddress));
            message.setSubject(subject);
            //Create the message part
            BodyPart messageBodyPart = new MimeBodyPart();
            //Fill the message
            if (msgBody.equals("")) {
                messageBodyPart.setText("Please find your file attached.");               
            } else {
                messageBodyPart.setText(msgBody);
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);
                //try{
                    //FileOutputStream fos = new FileOutputStream("contacts." + sFileExt);
                    //DataOutputStream dos = new DataOutputStream(fos);
                    //dos.writeUTF(attachmentContent);
                    //Part two is attachment
                    String mimeType = null;
                    //theoretically expand this later for other file types
                    DataHandler dataHandler = null;
                    if (sFileExt.equals("xls")) {
                        //convert attachmentContent to a byte[]
                        byte[] attachmentContentByteArray = attachmentContent.getBytes();
                        DataSource dsData = new MemoryDataSource(attachmentContentByteArray, "export.xls", "application/vnd.ms-excel");                       
                        dataHandler = new DataHandler(dsData);
                        //mimeType = "application/vnd.ms-excel";
                    } else {
                        //mimeType = "text/plain";
                        dataHandler = new DataHandler(attachmentContent,"text/plain");
                    messageBodyPart = new MimeBodyPart();
                    //with this constructor there does not appear to be a way to set the file name
                    messageBodyPart.setDataHandler(dataHandler);
                    //messageBodyPart.setContent(attachmentContent);                   
                    //messageBodyPart.setContentType(mimeType);
                    multipart.addBodyPart(messageBodyPart);
                    //dos.close();
                    //fos.close();
                //}catch(IOException e){
                //    logger.debug("error");
            //Put parts in message
            message.setContent(multipart);
            //Send message
            Transport.send(message);
        }catch(Exception e){
            logger.info("sendMailRob(String) " + e);
     Edited by: mimsc on Jul 21, 2009 11:21 AM

//with this constructor there does not appear to be a way to set the file name
messageBodyPart.setDataHandler(dataHandler);Well, that isn't a constructor. But I don't understand... the MimeBodyPart class DOES have a setFileName() method.

Similar Messages

  • I'm trying to read some XML data from temperature logger over my network. I'm using LabView version 2009 sp1. I'm using the URL Get Document Vi. It works fine when using Internet sites like google or foxnews etc...

    I'm trying to read some XML data from temperature logger over my network.  I'm using LabView version 2009 sp1.  I'm using the URL Get Document Vi.  It works fine when using Internet sites like google or foxnews etc...
    When I use it with my temperature logger most of the time I get an Error 66...but some times it does work and actually retrieves the document. 
    I can use the same address "http://172.22.21.68/XMLfeed.rb" (Internet Explorer or Google Chrome) in my browser and get a response every time.  When accessing from my browser the server in the temperature logger does take around 6 seconds to respond, but it does respond every time. 
    Is the URL Get Document Vi exceeding a timeout?  If so, where can I set it to wait longer?
    Attachments:
    Error 66.jpg ‏183 KB

    It looks like the TCP Buffered Read has a 2.5 sec timeout, I believe that is where I had trouble as well.  Try creating your own URL Get HTTP Doc vi in which you call URL Get Document in normal mode, with an appropriate number of characters to fetch (enough characters so that you capture all the important data in the XML file).
    Attachments:
    ex1.PNG ‏33 KB

  • Is it possible read fields on website from my JSP file

    Hi Frnds
    I want to know , Is it possible to read text fields on website from my JSP , I have website url and login details..
    1) How to open that URL with user username and PWD , I know only url and login details....apart from I dont have any information about that...
    2) I want to read one field values from that web site using my jsp , Is it possible ..which concepts will help me ...
    Plesae revert to mee...
    Thanks..frnds...

    It's perfectly possible, in essence you can just call openStream on the URL and the data will be fed to you. However then you hit the hard part, digging the bits you want out of the HTML you'll get. For this you'll need to start writing real Java rather than trying to stretch JSP to do stuff it shouldn't. I say again; write a Servlet. Beginners, who presumably come from PHP or ASP backgrounds, tend to try and do everything in JSPs, and avoid real Java classes. This is a very bad idea.
    In any case this kind of approach, mining data out of HTML pages, should be a last resort. First see if you can get your mail using POP3 or IMAP protocols. The gmail people will feel free to vary the structure of their HTML pages without warning, and your application will then fall in a heap. There's plenty of support for POP3 and IMAP in the java.mail package (not part of the standard install but easy to get).
    If you must read the HTML there are library classes that will help you. See the package java.swing.text.html.parser.

  • Trying to run java class files from my jsp

    I am having difficulty running java files from my jsp. I have compiled my two java classes and inserted them onto my server in the webapps/WEB-INF/classes/scripting directory and have imported scripting.* into my jsp page. The files both compiled ok before the class files were loaded onto the server but when I rty to run the jsp from the server, I keep getting a compiler error. Thanks in advance
    Iob

    Here are the few question
    1) Does your java classes which u created is declared under package scripting. *.class files are to be places under the WEB-INF/classes directory only. Not under scripting. But if you java classes say are under a package called a.b. Then you need to put under classes\a\b\.

  • Trying to pass Hidden/Session variables from 1 JSP to 3rd JSP

    Hellol JSP Gurus !!
    This is a question on how a hidden or a value of a session variable can be passed from 1 JSP to a 3rd JSP, with the 2nd JSP as a Processing page.
    For eg., here's the scenario
    I have a Login page which has the hidden variables. Once the user enters the Login information, the info is validated in a LoginP.jsp (say, its a Processing page for the Login user/passwd info), which does a sendRedirect to a 3rd (Final) JSP which displays the values of the hidden/session variables of the 1st JSP.
    In my case, for some reason, I am not able to see the value for the hidden or the session variables in the 3rd JSP - they are null values.
    I am attaching some Duke dollars to who ever gives me the right solution.
    Thanks a lot in advance

    Use strings to set attributes;You can store any serializable object in the session. I doubt this will actually change anything.
    Anything wrong with the above code ?Not that I can see ... A number of other things can explain why you're getting null values out of the session. For example :
    - You are not using the implicit session obj in the 3rd jsp, but creating a new one and thus overwriting the one created previously
    - the session timeout value is unusually low, and by the time you're getting to the 3rd jsp, the session is invalidated and you're getting nulls. Verify your server config, or call session.getMaxInactiveInterval() to check the value. Check also if the session is new ( session.isNew() )
    Somebody already pointed this out : If the client does not support cookies and URL rewriting is not enabled, no session ID is returned to the server on a request, which the server then perceives as a new session.
    - Another (remote?) possibility : your 3rd jsp belongs to another webapp (i.e you're redirecting to another app context).
    If nothing of the above applies, post the jsp code and we'll try to help.

  • Trying to read an XML file from the resources

    Hi,
    I am having a problem reading a file from the resources: In my project I have data.xml in my project resources folder. I tried the following and it does not work:
    File xsltFile = new File("resources/data.xml");
    or
    File xsltFile = new File("/resources/data.xml");
    Anybody could help please.
    Rgrds.

    Hi,
    I have tried the following and it does not work:
    URL url = this.getExternalContext().getResource("/resources/displayPassengers.xsl");
    File xsltFile = new File( url.getFile());
    However, the url object has the following properties:
    url.getPath() = "/server/benchmark/resources/displayPassengers.xsl";
    url.getFile() = "/server/benchmark/resources/displayPassengers.xsl";
    but I still can not read the xsltFile. The code are on the prerender() method of the page.
    Please let me know.
    Rgrds.

  • Issue with reading a xml file from xsl

    Hi,
    When I am trying to read a xml file from xsl, I am getting unwanted output.
    Following is the XSL:
    <?xml version="1.0" encoding="UTF-8" ?>
    <?oracle-xsl-mapper
      <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
      <mapSources>
        <source type="XSD">
          <schema location="../xsd/B2BMarketProperties.xsd"/>
          <rootElement name="ReceipentIDType" namespace="http://www.example.org"/>
        </source>
      </mapSources>
      <mapTargets>
        <target type="XSD">
          <schema location="../xsd/B2BMarketProperties.xsd"/>
          <rootElement name="ReceipentIDType" namespace="http://www.example.org"/>
        </target>
      </mapTargets>
      <!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.4.0(build 110106.1932.5682) AT [TUE DEC 03 16:06:03 EST 2013]. -->
    ?>
    <xsl:stylesheet version="1.0"
                    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                    xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                    xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
                    xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xmlns:ns0="http://www.example.org"
                    xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                    xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:med="http://schemas.oracle.com/mediator/xpath"
                    xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
                    xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
                    xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
                    xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                    xmlns:ora="http://schemas.oracle.com/xpath/extension"
                    xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                    xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
                    exclude-result-prefixes="xsi xsl ns0 xsd bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref ora socket ldap">
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:variable name="ReceipentID" select="document('../xsd/B2BMarketProperties.xml')"/>
      <xsl:template match="/">
        <ns0:ReceipentIDType>
        <xsl:for-each select="$ReceipentID">
          <ns0:ReceipentID>
            <xsl:value-of select="$ReceipentID"/>
          </ns0:ReceipentID>
          </xsl:for-each>
        </ns0:ReceipentIDType>
      </xsl:template>
    </xsl:stylesheet>
    Following is the XML ( B2BMarketProperties.xml)
    <?xml version="1.0" encoding="UTF-8" ?>
    <ReceipentIDType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://www.example.org B2BMarketProperties.xsd"
                     xmlns="http://www.example.org">
      <ReceipentID>123</ReceipentID>
      <ReceipentID>345</ReceipentID>
    </ReceipentIDType>
    The output i am getting with this code is
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:ReceipentIDType xmlns:ns0="http://www.example.org">
        <ns0:ReceipentID>123345</ns0:ReceipentID>
    </ns0:ReceipentIDType>
    But, I need output in the following format
    <ns0:ReceipentIDType xmlns:ns0="http://www.example.org">
        <ns0:ReceipentID>123</ns0:ReceipentID>
         <ns0:ReceipentID>345</ns0:ReceipentID>
    </ns0:ReceipentIDType>
    Could you guys let me know what i am doing wrong. Any help would be appreciated.
    Thanks,

    This worked for me :
      <xsl:template match="/">
        <ns0:ReceipentIDType>
          <xsl:for-each select="document('B2BMarketProperties.xml')/*:ReceipentIDType/*:ReceipentID">
            <xsl:variable name="count" select="position()"/>
            <ns0:ReceipentID>
              <xsl:value-of select="document('B2BMarketProperties.xml')/*:ReceipentIDType/*:ReceipentID[$count]"/>
            </ns0:ReceipentID>
          </xsl:for-each>
        </ns0:ReceipentIDType>
      </xsl:template>

  • Error While reading an Excel file from KM Folder.

    Hi Guru's,
    In my PDK Application I am trying to read an Excel file from KM Folder.
    Workbook workbook = Workbook.getWorkbook(new File("/irj/go/km/docs/documents/test/Test.xls"));
    It gives an error:
    Error:java.io.FileNotFoundException: \irj\go\km\docs\documents\test\Test.xls (The system cannot find the path specified)
    Details of appli:
    In my JspDynpage I am calling a utility Java file.
    There I have to read an  Excel and to passit to JSP.
    Details of jar files  used:
      jxl-2.6
      com.sap.security.api.jar
    Regards,
    Ram

    Hi,
    You are trying to read file wrong way. In the tutorial of Java Excel Api: "JExcelApi can read an Excel spreadsheet from a file stored on the local filesystem or from some input stream.". You are trying to read from file system. So you must get file input stream then you can read it. Please search forums KM file read.

  • Reading an XML file from a package .....

    I m trying to read an xml file from a package. The XML file is located on desktop (not on unix system). if i mention the path of the file in a package, is it sufficient ???. OR do i need to CREATE DIRECTORY in oracle and mention the file path in this directory ???
    I have granted CREATE directory permissions...
    If not any suggestion or advice is great ???
    Thank you!!

    BANNER
    1     Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    2     PL/SQL Release 11.1.0.6.0 - Production
    3     CORE     11.1.0.6.0     Production
    4     TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    5     NLSRTL Version 11.1.0.6.0 - Production
    Thank you !!!

  • Reading a text file from a URL

    I am having problems trying to read a text file from a URL.
    This is the code i have been using:
    package Java;
    import java.net.*;
    import java.io.*;
    public class Main_1 {
    public static void main(String[] args) throws Exception {
         URL myAddress = new URL("http://www.geocities.com/simonrobinson1/java/farrago.txt");
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        myAddress.openStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    but it returns an error saying:
    java.net.NoRouteToHostException: Operation timed out: no further information
    at java.net.PlainSocketImpl.socketConnect(Native Method) .....etc etc.
    Is this just a problem due to my network or is there something wrong with my code ????

    Altho you can access the file by typing the URL in a browser, geocities being a free web-hosting service don't like you to access the materials without seeing their ads. You have to find a way to trick it into thinking that you are indeed coming in from a web browser even tho you aren't.
    V.V.

  • Reading an XML file from package .....

    I m trying to read an xml file from a package. The XML file is located on desktop (not on unix system). if i mention the path of the file in a package, is it sufficient ???. OR do i need to CREATE DIRECTORY in oracle and mention the file path in this directory ???
    If not any suggestion or advice is great ???

    Depends upon the version of Oracle being used. Going from memory, I think it started with 10g that you had to CREATE DIRECTORY and then use that object in references to disk. It could have been 9i as I skipped that version. If you look at the documentation for whatever provided procedure you are calling it will tell you what it expects.
    As the code runs on the server the DB resides on, the data file will need to be network accessible from there in order for your code to read the file.

  • Reading external xml files from a jar

    Hi,
    I am trying to read an xml file from a jar (which is not present inside the jar ) .
    I am passing the file name as a string (like C:/folder/filename) to the SAXBuilder but it throwing
    unknown protocol: c error.
    i tried using an url , tried using a relative path but to no use.
    Need help in this regard urgently.
    TIA,
    Regards,
    Harsha

    Hi,
    Actually, my application needs to read two xml files , parse it, perform some operation and write
    the result to an output file.
    The names of the two xml files i mentioned, are specified in a properties file as absolute paths. (I even tried converting them to URIs)
    The xml files are in the same directory as the jar ( i dont know if it should matter as i am giving the absolute path).
    The main class reads the names of the files and passes the names as strings to the SAXBuilder.
    This is where i am getting an exception.
    Going by what you said, is it not possible for a java class to read a fie outside of the jar ? Is there no way to do this ? And right now i am not sure of how to go about this or if there's any work around . Any help would be appreciated.
    Kindly reply at the earliest
    TIA,
    Harsha

  • HTML from JSP

    Hi all,
    I got a problom,
    How can i get the output of a JSP page into a java class?.That is,The original JSP page sends the generated HTML to the browser.What i need is that generated HTML into a java class.
    Suppose i got an Email class ,
    String myContent = -------
    Email.setContent(mycontent);
    The string myContent should be the dynamically generated HTML from a JSP page.
    that is,
    String myContent = output from CustInfo.jsp.
    How to achieve this?.

    >
    String myContent = output from CustInfo.jsp.
    How to achieve this?.Open a URLConnection (or HttpURLConnection) to CustInfo.jsp,
    use the getInputStream() method to get a reference to the input stream for the jsp,
    read this stream (which will be the HTML for CustInfo.jsp) into the String.

  • How can I access to an EJB from a JSP, using a taglib?

    I'm trying to access to an EJB from a JSP using a taglib,
              and I get the example in
              http://java.sun.com/j2ee/j2sdkee/techdocs/guides/ejb/html/Advanced5.html.
              But I colund't run this example because in the weblogic Log appears many
              errors when I run the JSP.
              Can you help me?
              

    Backing files is an option. If you need to do it from the controller, you
    could use the Forward object. The forward object constructor can take a URL
    object as a parameter. This should do the trick.
    Regards,
    Kunal
    "Panji Aryaputra" <[email protected]> wrote in message
    news:[email protected]..
    Hi, you have to use backing file to get what you want. In my case, I am
    using a page backing file. Perhaps a portlet backing file can do thatalso.
    Cmiiw, the redirect header makes the page redirected only if the httpheader
    has not been sent to client. In your case, the header has been sent (i.e.
    the portal header.jsp has been displayed, etc). So the header need to be
    sent before anything else sent to client browser. This is where thebacking
    file comes handy.
    hth
    panji.a
    "A Hagen" <[email protected]> wrote in message
    news:[email protected]..
    I'm using Bea Workshop 8.1 and trying to perform a redirect from inside
    a
    portlet
    using HTTPServletResponse.sendRedirect(String url)... but nothing
    happens
    I tryed the same trick with a simple JSP, and that's ok, but portal
    pages
    obviously
    catch the redirect somehow.
    Please could you tell the correct way of redirecting the whole browser
    to
    another
    page from inside portlets?
    Thanks!!!

  • How can i render a dynamic html file in jsp page

    Hi everybody,
    i am trying to render a dynamic html file in jsp page with the result of querying a database.
    The response of the query is a xml document. And i have a stylesheet to transfer it to html.
    How can i render the html in a jsp file?

    I am using below code for HTML files
    private var appFile:String="index.html";
    if (StageWebView.isSupported)
                        currentState = "normal";
                        webView.stage = stage;
                        webView.viewPort = new Rectangle( 10, 130, (stage.stageWidth)-20, 750 );
                        var fPath:String = new File(new File("app:/assets/html/aboutus/"+ appFile).nativePath).url; 
                        webView.loadURL(fPath);
                        addEventListener(ViewNavigatorEvent.REMOVING,onRemove);
                    else {
                        currentState = "unsupported";
                        lblSupport.text = "StageWebView feature not supported";
    above code is working fine for me.

Maybe you are looking for

  • HT4650 my safari keeps crashing on my iMac. anyone know why. this keeps happening after 10 seconds or so. any ideas?

    SAFARI keeps crashing on my Imac. I have checked for virus software and appear to have none. I have checked the automatic safari address that loads, which mysteriously had a ,http/ with a coma infront of the default website address to load on safari.

  • Font Smoothing + Relative Positioning = Problem

    Hello, I ran across a strange inconsistency while designing a relative position based layout. My page has two divs, both relative positioned for height. They do not overlap. The page renders excellent in Firefox 3.5, and not bad in Chrome (though a l

  • Line-in mic for new iMac.

    I'm like 2-days new to mac-using so stay with me here. I just got the new iMac 24" 2.4ghz. I'm having a hard time getting my Logitech standard-in (non-USB) mic to work. The headphones work while plugged in, but the mic doesn't seem to be working. I c

  • Applications won't launch from dock

    I have recently had to re install tiger and was not able to use archive function so had to erase. Most files etc were OK and was able to shift stuff around between the macs hard drive and an external storage device. Lost of stuff got duplicated and I

  • Difficulty with Numbers selection (novice)

    How does one select a column or group of cells in Numbers without deleting cell contents?