Class Include

  extended by org.apache.struts2.components.Component
      extended by org.apache.struts2.components.Include

public class Include
extends Component

Include a servlet's output (result of servlet or a JSP page).

Note: Any additional params supplied to the included page are not accessible within the rendered page through the <s:property...> tag!


 <-- One: -->
 <s:include value="myJsp.jsp" />

 <-- Two: -->
 <s:include value="myJsp.jsp">
    <s:param name="param1" value="value2" />
    <s:param name="param2" value="value2" />

 <-- Three: -->
 <s:include value="myJsp.jsp">
    <s:param name="param1">value1</s:param>
    <s:param name="param2">value2<s:param>

 Example one - do an include myJsp.jsp page
 Example two - do an include to myJsp.jsp page with parameters param1=value1 and param2=value2
 Example three - do an include to myJsp.jsp page with parameters param1=value1 and param2=value2

Nested Class Summary
(package private) static class Include.PageOutputStream
          Implementation of ServletOutputStream that stores all data written to it in a temporary buffer accessible from Include.PageOutputStream.getBuffer() .
(package private) static class Include.PageResponse
          Simple wrapper to HTTPServletResponse that will allow getWriter() and getResponse() to be called as many times as needed without causing conflicts.
Field Summary
private static Log _log
private static String defaultEncoding
private static String encoding
private static boolean encodingDefined
private  HttpServletRequest req
private  HttpServletResponse res
protected  String value
Fields inherited from class org.apache.struts2.components.Component
actionMapper, COMPONENT_STACK, id, parameters, stack
Constructor Summary
Include(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
Method Summary
 void addParameter(String key, Object value)
          Adds the given key and value to this component's own parameter.
 boolean end(Writer writer, String body)
          Callback for the end tag of this component.
static String getContextRelativePath(ServletRequest request, String relativePath)
private static String getEncoding()
          Get the encoding specified by the property 'struts.i18n.encoding' in, or return the default platform encoding if not specified.
static void include(String aResult, Writer writer, ServletRequest request, HttpServletResponse response)
static void setDefaultEncoding(String encoding)
 void setValue(String value)
Methods inherited from class org.apache.struts2.components.Component
addAllParameters, altSyntax, copyParams, determineActionURL, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getComponentStack, getId, getParameters, getStack, popComponentStack, setActionMapper, setId, start, toString, usesBody
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


private static final Log _log


private static String encoding


private static boolean encodingDefined


protected String value


private HttpServletRequest req


private HttpServletResponse res


private static String defaultEncoding
Constructor Detail


public Include(ValueStack stack,
               HttpServletRequest req,
               HttpServletResponse res)
Method Detail


public static void setDefaultEncoding(String encoding)


public boolean end(Writer writer,
                   String body)
Description copied from class: Component
Callback for the end tag of this component. Should the body be evaluated again?

NOTE: will pop component stack.

end in class Component
writer - the output writer.
body - the rendered body.
true if the body should be evaluated again


public void setValue(String value)


public static String getContextRelativePath(ServletRequest request,
                                            String relativePath)


public void addParameter(String key,
                         Object value)
Description copied from class: Component
Adds the given key and value to this component's own parameter.

If the provided key is null nothing happens. If the provided value is null any existing parameter with the given key name is removed.

addParameter in class Component
key - the key of the new parameter to add.
value - the value assoicated with the key.


public static void include(String aResult,
                           Writer writer,
                           ServletRequest request,
                           HttpServletResponse response)
                    throws ServletException,


private static String getEncoding()
Get the encoding specified by the property 'struts.i18n.encoding' in, or return the default platform encoding if not specified.

Note that if the property is not initially defined, this will return the system default, even if the property is later defined. This is mainly for performance reasons. Undefined properties throw exceptions, which are a costly operation.

If the property is initially defined, it is read every time, until is is undefined, and then the system default is used.

Why not cache it completely? Some applications will wish to be able to dynamically set the encoding at runtime.

The encoding to be used.

Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.