I am trying to redirect to another action and pass a string parameter. This works without problems, but I have a problem with the encoding if I use German umlauts.
Here is my code: The first action has a field message with a getter and a setter. In action, I set the line.
private String message; public String action1() { message = "ΓΆ"; return SUCCESS; }
The second action has a field message with a getter and installer.
private String message;
Struts.xml defining 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 do not use redirection and do not show the message on jsp, everything works fine. The encoding is correct. If I redirect to another action, the message field installer sets the wrong line of the form "ΓΒΆ". I can not find a solution. Can someone help me?
Custom 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>
Class filter
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 either. Does anyone know this problem? Perhaps this is caused by Spring Security.
java struts2
Rafael
source share