Struts2 <s:url/>传递中文参数
jsp用<s:url>传递一个参数title到Action中,并从数据库中抽出title对应的表中的数据。但是我发现title为英文时正常取出数据,但是中文时就什么都没有。会不会时编码问题啊?url地址是乱码啊。
action如下:
Java code
HttpServletRequest request= ServletActionContext.getRequest();
String title;
try {
title = new String(request.getParameter("title").getBytes("ISO-8859-1"),"utf8");
List<Notice> list= new NoticeDAO().listByTitle(title);
request.setAttribute("list", list);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "success";
------解决方案--------------------在web.xml用spring把编码统一额
------解决方案-------------------- <filter>
<filter-name>CharsetFilter</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>
<filter-mapping>
<filter-name>CharsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>