日期:2014-05-19  浏览次数:20813 次

jsp 向struts传值乱码怎么解决啊 ?
在网上找了很多方法都不管用,下面是我的代码:
jsp:
<form id="form1" name="form1" method="post" action="EleSearchAction.action">
<div class="r_search">
<h3>
查询课程
</h3>
课程编号
<input name="couId" id="couId" type="text" class="kuang" id="couName" value="<s:property value="couId"/>" />
课程名称
<input name="couName" id="couName" type="text" class="kuang" id="couName" value="<s:property value="couName"/>" />
状态
<select name="couState" id="couState">
<option
<s:if test="'--请选择--'.equals(couState)">selected="selected"</s:if>>
--请选择--
</option>
<option
<s:if test="'激活'.equals(couState)">selected="selected"</s:if>>
激活
</option>
<option
<s:if test="'禁用'.equals(couState)">selected="selected"</s:if>>
禁用
</option>
<option
<s:if test="'过期'.equals(couState)">selected="selected"</s:if>>
过期
</option>
</select>

<input name="elesearch" type="submit" class="anniu_cx" value=""
id="elesearch" />


action:
  其他的就不贴了:
  private ElectiveEbi eleEbi=null;
private String couName;
private String couId;
private int page;
private PageBean pageBean;
private String couState;


public String getCouState() {
return couState;
}



public void setCouState(String couState) {
this.couState = couState;
}



public String getCouName() {
return couName;
}



public void setCouName(String couName) {
this.couName = couName;
}



public String getCouId() {
return couId;
}



public void setCouId(String couId) {
this.couId = couId;
}


  System.out.println(couState);
在action中输出couState时就乱码了!

------解决方案--------------------
乱码有好多种,没看到你贴出关于页面编码或者处理请求参数乱码的代码,strust2提供了一个中文编码过滤器你先试下,具体代码如下:
<!-- 中文过滤器 -->
<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>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>