Struts has a <bean:include> tag - not used it myself, but the docs say it
performs an internal dispatch to a component or URL and stores the response
in a bean. Maybe you could use that as part of a solution.

http://jakarta.apache.org/struts/userGuide/struts-bean.html#include


I have a simple tag (StoreTag) which does something similar, except you
embed the jsp stuff you want in the tag. So you could set up a jsp with this
tag and then in your action use the RequestDispatcher to include the jsp and
put the output into a bean. Something like:


 ------SamplePage.jsp-----
 <custom:store name="myForm" property="samplePage" scope="session">
     ------ format your jsp stuff here -----
 </custom:store>


-------in your Action.execute()-------
// Get formatted email content
RequestDispatcher rd =
servlet.getServletContext().getRequestDispatcher("myJspPage.jsp");
rd.include(request, response);
String samplePage= form.getSamplePage();

In this example, you would need so set up the "samplePage" as a property in
your ActionForm.

----------StoreTag Source-----------------
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.RequestUtils;
import org.apache.commons.beanutils.BeanUtils;

public class StoreTag extends BodyTagSupport {

protected String name = null;
protected String property = null;
protected String scope = null;

public StoreTag() {
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setProperty(String property) {
this.property = property;
}
public String getProperty() {
return property;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getScope() {
return scope;
}
public int doAfterBody() throws JspException {
String value = null;
if (bodyContent != null) {
value = bodyContent.getString().trim();
}
if (property == null) {
pageContext.setAttribute(name, value, RequestUtils.getScope(scope));
} else {
// find the bean
Object bean = RequestUtils.lookup(pageContext, name, scope);
if (bean == null)
throw new JspException("Cannot find bean '"+name+"' in scope '"+scope+"'");
try {
BeanUtils.setProperty(bean, property, value);
}
catch (Exception ex) {
throw new JspException("Error setting property '"+property+"' on bean
'"+name+"' in scope '"+scope+"': "+ex);
}
}
return (SKIP_BODY);
}
public void release() {
name = null;
property = null;
scope = null;
}
}

----- Original Message ----- 
From: "Amine Bousta" <[EMAIL PROTECTED]>
Sent: Monday, April 19, 2004 11:00 AM


> Hello,
>
> I'm trying to write a struts action that could save in a database and
> send by e-mail the output of a JSP page.
> This JSP page needs attributes values that are stored in the session
> context. In other words, I need ServletContext of the struts action and
> the JSP page to be the same.
>
> I first tried to use the Java "URL" object to perform this action but it
> creates a separate ServletContext.
>
> I didn't find any solution to this issue on the internet.
> Does anybody can help me?...
>
> Amine



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to