例如:
在表单里输入的是 •    可是提交到Action后,ActionForm里得到的却是 • 
导致插入到数据库里的也是 •  怎么办?
怎样才能让ActionForm得到的是 •  ,而不是 • ?

解决方案 »

  1.   

    /** 
    * 防范SQL注入漏洞,检测输入的字符 
    * 需要检测的特殊字符及字符串有:",","-","/","\\","'","%",""" 
    * @param  strInput 待检测的字符 
    * @author Tony Lin Added on 2008-10-21 
    */ 
    function checkInputChar(strInput){ 
    var forbidChar = new Array(",","-","/","\\","'","%","\""); 
    for (var i = 0;i < forbidChar.length ; i++){ 
      if(strInput.indexOf(forbidChar[i]) >= 0){ 
                alert("您输入的信息: "+strInput+" 中含有非法字符: "+forbidChar[i]+" 请更正!"); 
          return false; 
      } 

    return true; 
    } /** 
    * 遍历form内元素text类型检测字符合法性,此方法结合 checkInputChar(strInput)使用 
    * JSP页面只要调用该方法,并传入form名即可自动完成该form内所有元素字符的检测 
    * @param  formName 待检测的form名 
    * @author Tony Lin Added on 2008-10-21 
    */ 
    function validationFormText(formName){ 
    var actionForm; 
    //alert(typeof(formName)); 
    if(typeof(formName)){ 
            actionForm = formName; 
    }else{ 
      actionForm = document.forms[0]; 

    for (var i=0;i<actionForm.length;i++ ){ 
      if (actionForm.elements[i].value != "" && actionForm.elements[i].type == "text"){ 
       //alert(actionForm.elements[i].value); 
                if(!checkInputChar(actionForm.elements[i].value)){ 
        actionForm.elements[i].focus(); 
        return false; 
       } 
      } 

    return true; 
    } 在JSP页面的查询事件中增加如下代码即可: 
    //检测form内所有text元素的字符合法性 
    if(!validationFormText(form1)){ 
        return(false); 
    }
      

  2.   

    转换编码试试:例如
    String name = request.getParameter("name");  
    name = java.net.URLDecoder.decode(name);   
    name=CoDataTran.chineseToUnicode(name);
    自己试试,单个特殊字符应该可以拿到,但是中文有可能乱码,自己处理一下。
      

  3.   

    显示     实体名称     实体编号
     <       &lt;       &#60;
     ∴    &there4;    &#8756;
     •      &bull;     &#8226;这是HTML对转义字符的处理
    该怎么办呢?总不能在ActionForm里对所有的转义字符 replaceAll() 吧?
      

  4.   

    一直采用UTF-8编码没有出现过这种问题
      

  5.   


    public static String format(String content) {
    content = content.replaceAll(" ", "&nbsp;&nbsp;").replaceAll("<",
    "&lt;").replaceAll(">", "&gt;").replaceAll("\r\n", "<br>"); return content;
    }试试这个,我觉得行!
      

  6.   

     public String codeToString(String str)
      {//处理中文字符串的函数
       String s=str;
        try
          {
            byte tempB[]=s.getBytes("ISO-8859-1");
            s=new String(tempB);
            return s;
           }
        catch(Exception e)
       {
         return s;
       }
      }String t1=codeToString((String)request.getParameter("txt1"));//获取组件值