Package org.apache.struts2.result
Class HttpHeaderResult
java.lang.Object
org.apache.struts2.result.HttpHeaderResult
- All Implemented Interfaces:
Serializable
,Result
A custom Result type for setting HTTP headers and status by optionally evaluating against the ValueStack. This result can also be used to send an error to the client. All the parameters can be evaluated against the ValueStack.
This result type takes the following parameters:
- status - the http servlet response status code that should be set on a response.
- parse - true by default. If set to false, the headers param will not be parsed for Ognl expressions.
- headers - header values.
- error - the http servlet response error code that should be set on a response.
- errorMessage - error message to be set on response if 'error' is set.
Example:
<result name="success" type="httpheader"> <param name="status">204</param> <param name="headers.a">a custom header value</param> <param name="headers.b">another custom header value</param> </result> <result name="proxyRequired" type="httpheader"> <param name="error">305</param> <param name="errorMessage">this action must be accessed through a proxy</param> </result>
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
This result type doesn't have a default param, null is ok to reduce noise in logs -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an HTTP header to the responsevoid
execute
(ActionInvocation invocation) Sets the optional HTTP response status code and also re-sets HTTP headers after they've been optionally evaluated against the ValueStack.Returns a Map of all HTTP headers.int
void
Sets the http servlet error code that should be set on the responsevoid
setErrorMessage
(String errorMessage) Sets the error message that should be set on the reponsevoid
setParse
(boolean parse) Sets whether or not the HTTP header values should be evaluated against the ValueStack (by default they are).void
setStatus
(int status) Sets the http servlet response status code that should be set on a response.
-
Field Details
-
DEFAULT_PARAM
This result type doesn't have a default param, null is ok to reduce noise in logs
-
-
Constructor Details
-
HttpHeaderResult
public HttpHeaderResult() -
HttpHeaderResult
public HttpHeaderResult(int status)
-
-
Method Details
-
setError
Sets the http servlet error code that should be set on the response- Parameters:
error
- the Http error code- See Also:
-
HttpServletResponse.sendError(int)
-
setErrorMessage
Sets the error message that should be set on the reponse- Parameters:
errorMessage
- error message send to the client- See Also:
-
HttpServletResponse.sendError(int, String)
-
getHeaders
Returns a Map of all HTTP headers.- Returns:
- a Map of all HTTP headers.
-
setParse
public void setParse(boolean parse) Sets whether or not the HTTP header values should be evaluated against the ValueStack (by default they are).- Parameters:
parse
- true if HTTP header values should be evaluated against the ValueStack, false otherwise.
-
setStatus
public void setStatus(int status) Sets the http servlet response status code that should be set on a response.- Parameters:
status
- the Http status code- See Also:
-
HttpServletResponse.setStatus(int)
-
getStatus
public int getStatus() -
addHeader
Adds an HTTP header to the response- Parameters:
name
- header namevalue
- header value
-
execute
Sets the optional HTTP response status code and also re-sets HTTP headers after they've been optionally evaluated against the ValueStack.
-