Iv�n,
Here's the custom tag to copy the JSP content:
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
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html