public class StreamResult extends StrutsResultSupport
A custom Result type for sending raw data (via an InputStream) directly to the HttpServletResponse. Very useful for allowing users to download content.
This result type takes the following parameters:
text/plain
).inline
, values are typically
attachment;filename="document.pdf".inputStream
).1024
).true
)
These parameters can also be set by exposing a similarly named getter method on your Action. For example, you can
provide getContentType()
to override that parameter for the current action.
Example:
<result name="success" type="stream"> <param name="contentType">image/jpeg</param> <param name="inputName">imageStream</param> <param name="contentDisposition">attachment;filename="document.pdf"</param> <param name="bufferSize">1024</param> </result>
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowCaching |
protected int |
bufferSize |
protected String |
contentCharSet |
protected String |
contentDisposition |
protected String |
contentLength |
protected String |
contentType |
static String |
DEFAULT_PARAM |
protected String |
inputName |
protected InputStream |
inputStream |
protected static org.apache.logging.log4j.Logger |
LOG |
DEFAULT_URL_ENCODING, parseLocation
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
Constructor and Description |
---|
StreamResult() |
StreamResult(InputStream in) |
Modifier and Type | Method and Description |
---|---|
protected void |
doExecute(String finalLocation,
ActionInvocation invocation)
Executes the result given a final location (jsp page, action, etc) and the action invocation
(the state in which the action was executed).
|
boolean |
getAllowCaching() |
int |
getBufferSize() |
String |
getContentCharSet() |
String |
getContentDisposition() |
String |
getContentLength() |
String |
getContentType() |
String |
getInputName() |
void |
setAllowCaching(boolean allowCaching)
Set allowCaching to false to indicate that the client should be requested not to cache the data stream.
|
void |
setBufferSize(int bufferSize) |
void |
setContentCharSet(String contentCharSet) |
void |
setContentDisposition(String contentDisposition) |
void |
setContentLength(String contentLength) |
void |
setContentType(String contentType) |
void |
setInputName(String inputName) |
conditionalParse, conditionalParseCollection, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse
protected static final org.apache.logging.log4j.Logger LOG
public static final String DEFAULT_PARAM
protected String contentType
protected String contentLength
protected String contentDisposition
protected String contentCharSet
protected String inputName
protected InputStream inputStream
protected int bufferSize
protected boolean allowCaching
public StreamResult()
public StreamResult(InputStream in)
public boolean getAllowCaching()
public void setAllowCaching(boolean allowCaching)
allowCaching
- Enable caching.public int getBufferSize()
public void setBufferSize(int bufferSize)
bufferSize
- The bufferSize to set.public String getContentType()
public void setContentType(String contentType)
contentType
- The contentType to set.public String getContentLength()
public void setContentLength(String contentLength)
contentLength
- The contentLength to set.public String getContentDisposition()
public void setContentDisposition(String contentDisposition)
contentDisposition
- the Content-disposition header value to use.public String getContentCharSet()
public void setContentCharSet(String contentCharSet)
contentCharSet
- the charset to use on the header when sending the streampublic String getInputName()
public void setInputName(String inputName)
inputName
- The inputName to set.protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception
StrutsResultSupport
doExecute
in class StrutsResultSupport
finalLocation
- the location (jsp page, action, etc) to go to.invocation
- the execution state of the action.Exception
- if an error occurs while executing the result.StrutsResultSupport.doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation)
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.