I try to redirect to another action and to transmit a string parameter. This works without problems, but I have a coding problem if I am using german umlauts.
Here is my code: First action has a field message with getter and setter. In the action I set the String.
private String message;
public String action1()
{
message = "ö";
return SUCCESS;
}
Second action has a field message with getter and setter too.
private String message;
Struts.xml with the definition of the both actions
<action name="action" method="action1" class="de.samba.control.actions.Action1">
<result name="success" type="redirectAction">
<param name="actionName">action2</param>
<param name="message">${message}</param>
<action name="action2" class="de.samba.control.actions.Action2">
<result name="success">/pages/showMessage.jsp</result>
If I don´t using redirection and show the message on a jsp, all works fine. The coding is correct. If I redirect to another action the setter of the message field set the wrong formattet string "ö". I cannot found the solution. Can somebody help me please?
Own Filter:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>de.samba.control.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
Filter-class
public class CharacterEncodingFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain next) throws IOException, ServletException
{
String encoding = request.getCharacterEncoding();
if (encoding == null || encoding.length() == 0)
{
request.setCharacterEncoding("UTF-8");
}
encoding = request.getCharacterEncoding();
next.doFilter(request, response);
}
}
Then I tried this filter:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
This does not work too. Do somebody know this problem? Maybe it is caused by Spring Security.
The redirect result type calls the standard response. sendRedirect() method, causing the browser to create a new request to the given location.
ActionSupport class implements a no. of interfaces like Action, Validateable, LocaleProvider and Serializable etc. It is more commonly used instead of Action interface.
You can use post-login Actions to redirect users before an authentication transaction is complete. This lets you implement custom authentication flows that require additional user interaction beyond the standard login form.
The problem was a tomcat issue and not a struts issue. The solution is to set the URIEncoding of the Connector to "utf-8" in server.xml. See http://struts.apache.org/2.0.14/docs/how-to-support-utf-8-uriencoding-with-tomcat.html
Maybe the problem is in the way the url (which makes action invocation) is generated. For instance, if the url generations is something like below, be aware of the attribute escape :
<s:url namespace="/" action="recursoNuevo" var="recursoNuevo" >
<s:param name="contextPath">
<s:property value="contextPath" escape="false"/>
</s:param>
</s:url>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With