<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <jsp:include page="../default.jsp"></jsp:include>
    <jsp:include page="../validator.jsp"></jsp:include>
    
    <script type="text/javascript">
    
    function submitAction(){
       var cellphone = $("input[name='groupname']").val();
       if(new RegExp(regexEnum.notempty).test(cellphone)){
          $.getJSON(__ctxPath+"/mdaoGroupAction.do?op=add&groupname="+cellphone+"&common=<bean:write name='form' property='common'/>",function(json){
            if(json.su)
               alert("记录添加成功");
            else            
               alert("记录添加失败:"+json.fa);
          })
       }else{
         alert("请填写组名称");
       }
    }
    </script>
  </head>
 <body>
    <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" background="images/right_bg.jpg">
  <tr>
    <td height="32" align="left" valign="top" background="images/title_bg.gif">
 <table width="400" height="32" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="40"><img src="images/title_left.gif" width="40" height="32" /></td>
        <td width="360" align="left" valign="middle" class="hei">
         <a href="javascript:;">通讯录管理</a><font style="font-weight: bold;font-family:arial;">&nbsp;&nbsp;&gt;&gt;&nbsp;&nbsp;</font><a href="<%=request.getContextPath()%>/mdaoMemberAction.do?op=list&common=<bean:write name='form' property='common'/>" onclick="javascript:" ><logic:equal value="common" name='form' property="common">公共通讯录</logic:equal><logic:equal  value="self"   name='form' property="common">个人通讯录</logic:equal></a><font style="font-weight: bold;font-family:arial;">&nbsp;&nbsp;&gt;&gt;&nbsp;&nbsp;</font><a href="<%=request.getContextPath()%>/mdaoGroupAction.do?op=list&common=<bean:write name='form' property='common'/>" >通讯组管理</a><font style="font-weight: bold;font-family:arial;">&nbsp;&nbsp;&gt;&gt;&nbsp;&nbsp;</font><a href="javascript:void(0);">添加组</a>
        </td>
      </tr>
     </table>
</td>
  </tr>
  <tr>
    <td align="left" valign="top">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td width="9" background="images/right_l.gif"></td>
       <td>
    <div class="right_box">
     <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
   <td align="center" valign="middle" style="padding:13 20 0 20px;text-align:center;">
   <html:form action="mdaoGroupAction.do?op=add" styleId='form1' onsubmit="submitAction();return false;">
     <html:hidden name="form" property="common"/>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
      <td height="auto" align="left" valign="top" bgcolor="#EEF7FD">
   <table width="100%" height="24" border="0" cellpadding="0" cellspacing="0" bgcolor="#D8D8D8">
                 <tr>
                   <td height="24" align="left" valign="top" background="images/htbj.gif" bgcolor="#D8D8D8"><table width="83" height="21" border="0" cellpadding="0" cellspacing="0">
                       <tr>
                         <td align="left" valign="bottom"><font color="#FFFFFF">&nbsp;&nbsp;添加组</font></td>
                       </tr>
                   </table></td>
                 </tr>
               </table>
  </td>
     </tr>
     <tr>
      <td height="66" align="left" valign="middle">
   <table width="500" border="0" cellspacing="0" cellpadding="0">
                <tr>
                 <td width="130" height="24">&nbsp;</td>
                 <td width="270" align="left" valign="middle"><font color="#4F6D8A"><B>组名字:</B></font>
                  <html:text name='form' property="groupname" styleId="groupname" style="width:180px;" /></td>
                 <td width="47" align="left" valign="middle"> 
                  <input name="sb1" id='imgSubmitId' type="submit" style="border:0px; background:url(images/txz_cz.gif) no-repeat; width:47px; height:20px; color:#516F8C;" value="添 加" /></td>
                 <td width="6"></td>
                 <td width="47" align="left" valign="middle"><input type="reset"  style="border:0px; background:url(images/txz_cz.gif) no-repeat; width:47px; height:20px; color:#516F8C;" value="重 置" /></td>
                </tr>
               </table>
  </td>
     </tr>
            </table>
           </html:form>
           </td>
          </tr>
         </table>
        </div>
   </td>
      </tr>
     </table>
</td>
  </tr>
</table>
  </body>
</html>

解决方案 »

  1.   

    上边是我的页面,这个是action
    public class MdaoGroupAction extends com.mdao.emap.webapp.action.BaseAction{
    public ActionForward add(ActionMapping mapping,ActionForm iform,HttpServletRequest request,HttpServletResponse response) throws Exception{
            MdaoGroupManager mgr=(MdaoGroupManager)getBean("mdaoGroupManager");
            MdaoGroupForm form=(MdaoGroupForm)iform;
            String common=form.getCommon();
            conditions.put("accountid",common.equals("common") ? -1 : getUser(request).getSerialno().intValue());
            conditions.put("groupname",form.getGroupname());
            List<MdaoGroup> lst=mgr.getListByCondition(conditions);
            JsonObject json=new JsonObject();
            if( lst.isEmpty() ){
                MdaoGroup model=new MdaoGroup();
                model.setGroupname(form.getGroupname());
                model.setAccountid(form.getCommon().equals("common") ? -1 : getUser(request).getSerialno().intValue());
                mgr.save(model);
                log(request,"",Constants.LOG_TYPE_ADD);
                request.setAttribute("url","/mdaoGroupAction.do?op=list");
                json.addProperty("su",1);
            }else{
                json.addProperty("fa","该组信息已经存在,请更换!");
            }
            writeJson(json,request,response);
            return mapping.findForward(pageJson);
        }
    }
    我调试了下,从form里取到的groupname直接就是乱码,这个怎么处理啊,高手指点下。
      

  2.   

    如果在开发环境下乱码的话,检查下自己的开发工具的编码设置,如果是发布后出现乱码的话,检查下自己的web容器的编码方式,应该可以解决。
      

  3.   

    web.xml 有没有配置 编码监听
    <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> 
      

  4.   

    request.setCharacterEncoding("utf-8");
      

  5.   

    我找到原因了,<script type="text/javascript">
        
      function submitAction(){
      var cellphone = $("input[name='groupname']").val();
      if(new RegExp(regexEnum.notempty).test(cellphone)){
      $.getJSON(__ctxPath+"/mdaoGroupAction.do?op=add&groupname="+cellphone+"&common=<bean:write name='form' property='common'/>",function(json){
      if(json.su)
      alert("记录添加成功");
      else   
      alert("记录添加失败:"+json.fa);
      })
      }else{
      alert("请填写组名称");
      }
      }
      </script>
    我给这个js去掉后添加中文没有乱码,但是没有这个js的话其他地方就报错了