为什么“冮”字提交就会变成 ?(乱码)其他中文就没有问题!
我调试了下。到Action类。前就变成乱码了。问题应该出现在。JSP提交上。我找不到办法解决。请帮帮忙吧!
<%@ page contentType="text/html; charset=gb2312" language="java" 
import="java.sql.*,java.util.*,com.hibernate.Zxzm;" errorPage=""%>
<%@ taglib uri="struts-bean.tld" prefix="bean"%>
<%@ taglib uri="struts-html.tld" prefix="html"%>
<%@ taglib uri="struts-logic.tld" prefix="logic"%>
<%@ taglib uri="struts-nested.tld" prefix="nested"%>
<html>
<head>
<title>字幕设置</title>
<script type="text/javascript" src="js/selectDateTime.js"></script>
<script type="text/javascript" src="js/myValidate.js"></script>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {alert(alerttxt);return false}
  else {return true}
  }
}function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(codeBody,"请输入字幕")==false)
    {codeBody.focus();return false}
    if (validate_required(endDate,"请选择结束日期")==false)
    {endDate.focus();return false}
  }
}
</script>
</head>
<body>
<p>
<html:link action="zxzmTableOldToTable">字幕查询</html:link>&lt;&gt; 
设置字幕&lt;&gt;
当前用户 :<%=session.getAttribute("drMyName")%>
</p>
<html:form action="/zxzmSave" method="post" onsubmit="return validate_form(this)">
<table width="900" border="1">
<tr>
<td >
<html:textarea property="codeBody" value="" cols="128" rows="5" name="codeBody"></html:textarea>
</td>
</tr>
<tr>
<td>
结束日期:<html:text property="endDate" maxlength="10" onfocus="selectDate(this)" readonly='true' size="10" /> 
<html:select property="duanshu" name="duanshu" value="0">
<html:option value="0">第一段</html:option>
<html:option value="1">第二段</html:option>
</html:select>
<html:submit value="保存字幕"></html:submit>
</td>
</tr>
</table>
</html:form>
<font color="#ff0000" size="6"><strong><%if(request.getAttribute("dataAddTag")!=null){%><%=request.getAttribute("dataAddTag")%><%}%></strong></font>
<label id="aaa" ></label>
</body>
</html>

解决方案 »

  1.   


    //取第一个参数之前
    request.setCharacterEncoding("GBK");
      

  2.   

    public class StringUtil {
    private static Log _$2055 = LogFactory.getLog("com.firsttech.anji.UI"); public StringUtil() {
    } public static String encode(String str) {

    String eStr = null;
    if (str == null) { return str;
    }
    try {
                eStr = new String(str.getBytes("ISO8859_1"), "UTF8");
            }catch (UnsupportedEncodingException ex) {
    _$2055.error("StringUtil.encode() ", ex);
    }
    return eStr;
    }
    }
     写这个类  调那个方法, 直接吧string传进去。