Gunter,
I think the best way to handle it is to use a custom tag. Here's a response
that I posted to the Servlet Interest group to someone who wanted to do the
same thing.

-Richard

CopyTag.java
--------------------
package utiltags;

import java.io.*;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */

public class CopyTag extends BodyTagSupport {
  public int doAfterBody() throws JspException {
    try {
      String content = bodyContent.getString();
      pageContext.setAttribute(id,content);
      bodyContent.writeOut(getPreviousOut());
    }
    catch(java.io.IOException e) {
      throw new JspException(e.getMessage());
    }
    return SKIP_BODY;
  }
}


CopyTagInfo.java
------------------------
package utiltags;

import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.VariableInfo;

/**
 * <p>Title: CopyTagInfo.java</p>
 * <p>Description: A TagInfo class for the CopyTag tag</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: Single Track Software</p>
 * @author Richard Yee
 * @version 1.0
 */

public class CopyTagInfo extends TagExtraInfo {
  public VariableInfo[] getVariableInfo(TagData data) {
    return new VariableInfo[] {
      new VariableInfo(data.getId(), // scripting var's name
      "java.lang.String", // variable's type
      true,
      VariableInfo.AT_END)
    };
  }
}

UtilTag.tld
---------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
        "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd";>
  <!-- a tag library descriptor -->
  <taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>utiltag</shortname>
    <uri></uri>
    <info>A library of utility tags</info>
    <tag>
      <name>copyTag</name>
      <tagclass>utiltags.CopyTag</tagclass>
      <teiclass>utiltags.CopyTagInfo</teiclass>
      <bodycontent>JSP</bodycontent>
      <attribute>
        <name>id</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
      </attribute>
    </tag>
   </taglib>


utiltagtest.jsp
-------------------
<%@ taglib uri="utiltags" prefix="util" %>
<html>
<head>
<title>CopyTag Test</title>
</head>
<util:copyTag id='myVar'>
<body>
Hello World!
</body>
</util:copyTag>
<br>The value of myVar = '<%= myVar %>'
</html>


Note: the output of the jsp in the browser is:
Hello World!
The value of myVar = ' Hello World! '

This is not exactly what is expected. However, if you view the source, the
expected output is returned:
<html>
<head>
<title>CopyTag Test</title>
</head>

<body>
Hello World!
</body>

<br>The value of myVar = '
<body>
Hello World!
</body>
'
</html>

The difference is caused by the fact that html tags need to be escaped in
order to be visible to the user in the browser and not processed by the
browser.

If you use the mailer taglib which is available from www.jsptags.com, the
example jsp would then be:

<%@ taglib uri="utiltags" prefix="util" %>
<util:copyTag id='myVar'>
<html>
<head>
<title>CopyTag Test</title>
</head>
<body>
Hello World!
</body>
</html>
</util:copyTag>
<mt:mail server="your_server_name" to="destination@address"
from="your_sender_address" subject="your_subject">
<mt:message><%= myVar %></mt:message>
<mt:send/>
</mt:mail>

By using custom tags, you get a reusable piece of code that can be used
across multiple JSP's and avoid having scriptlets in your JSP.

Regards,

Richard



At 11:25 AM 6/26/2002 -0600, you wrote:
OK, i finally found it, look at the Example:

String URLString = "http://XXX.com/someJSP?AAA="; + aaa;

URL url = new URL(URLString);
URLConnection conn = url.openConnection();
DataInputStream in = new DataInputStream(conn.getInputStream());

while ((linea = in.readLine()) != null)
       Message+=linea + "\n";

So, Message has all the content

Now, about the images (relative paths), well, here's a web page where it
explain it, but it's a little bit complicated, maybe there's a simple way to
do it, if somebody know, welcome he is.

http://www.jguru.com/faq/view.jsp?EID=741046
At 02:46 PM 10/22/2002 +0200, you wrote:
Hello,

How can I get the html that is being generated by a jsp-page into a
string value? The thing that I want to do is to send an email with an
attachment that is a dynamically created webpage. The webpage is a
jsp-page.
I've done that with other serversided scripts but have no idea how I can
do this with JSP. I'm thinking about making a new HttpServletRequest or
hoping to find a 'GetGenerated("test.jsp")' or
'IncludeGenerated("test.jsp")'.

Any help is welcome pls!
Greetings,
Gunter.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com

Reply via email to