jsp到action 传递url时中文出现乱码

先在jsp编码,再在action中解码

encodeURI(encodeURI("中文"))编码

URLDecoder.decode(request.getParameter("参数名"),"UTF-8");完成解码。

例如:  url:"qtypenums.action?typeid=<s:property value='typeid'  escape='false'/>&qmobile=<s:property value='qmobile'  escape='false'/>&qname="+encodeURI(encodeURI('<s:property value='qname'  escape='false'/>'))+"&qattr1="+encodeURI(encodeURI('<s:property value='qattr1'  escape='false'/>'))+"&qattr2="+encodeURI(encodeURI('<s:property value='qattr2'  escape='false'/>'))+"&qattr3="+encodeURI(encodeURI('<s:property value='qattr3'  escape='false'/>')),

在action中解码

String qname=this.getQname();
        String qattr1=this.getQattr1()==null?"":this.getQattr1();
        String qattr2=this.getQattr2()==null?"":this.getQattr2();
        String qattr3=this.getQattr3()==null?"":this.getQattr3();
        String qname1="";
        String qattr11="";
        String qattr21="";
        String qattr31="";
        try{
            qname1=URLDecoder.decode(qname,"UTF-8");
            qattr11=URLDecoder.decode(qattr1,"UTF-8");
            qattr21=URLDecoder.decode(qattr2,"UTF-8");
            qattr31=URLDecoder.decode(qattr3,"UTF-8");
        }catch(Exception w){}

原文地址:https://www.cnblogs.com/danica/p/2123556.html