为什么用JAVA的HTTP递交给JAVAServlet生成JSP页面的时候,中文变成乱码了,我已经用了CHARSET=UTF-8等等了

    技术2022-05-11  65

    发表于: 2007-09-19 14:32:41 楼主 请问高手为什么用JAVA的HTTP递交给JAVAServlet生成JSP页面的时候,中文变成乱码了,我已经用了CHARSET=UTF-8等等了。 如果你用struts可以参考一下 jsp:       <head >                 <title > <bean:message   key="statusercompose.application.title"   bundle="statusercompose"/ > </title > <% request.setCharacterEncoding("UTF-8"); //   系统的环境变量 String   path   =   request.getContextPath();     String   basePath   =   request.getScheme()   +   "://"   +   request.getServerName()   +   ":"   +   request.getServerPort()   +   path;     String   servletPath   =   request.getServletPath();     % > <script   type="text/javascript" > var   rootUrl=" <%=basePath% >"; // var   GEId   =   function(eID)   { return   document.getElementById(eID); } // function   check_form(){ var   issueNo=GEId("_issueNo").value; if   (issueNo==""){ alert("请输入期号!"); GEId("_issueNo").focus(); }else{ var   showType=GEId("showType").value; var   province=GEId("__province").value; var   city=GEId("__city").value; var   county=GEId("__county").value; GEId("proCode").value=province; GEId("cityCode").value=city; GEId("countyCode").value=county; if   (showType==0){ document.forms[0].action=" <%=basePath% >/statUserCompose.do?method=getStatUserCompose_Table"; document.forms[0].submit(); }else{ document.forms[0].action=" <%=basePath% >/statUserCompose.do?method=getStatUserCompose_Chart"; document.forms[0].submit(); } } } </script > </head >     <html:form   styleId="form1"   action="/statUserCompose"   method="post" >     <input   type="hidden"   name="pressCode" >     <input   type="hidden"   name="pressName" >     </html:form > <input   type="button"   class="bt-2ch"   name="b_query"   value="查询"   onClick="check_form();" >   注:pressName是中文,我要把它传到后台做处理;用http参数的方式和用加过滤器的方式得到的结果都是乱码 通过用js以表单提交的方式进行处理,就不会出现乱码   后台: /*以表格的方式显示*/ public   ActionForward   getUserCompose_Table(ActionMapping   mapping,   ActionForm   form, HttpServletRequest   request,   HttpServletResponse   response)   throws   WebException{ sucForm   =   (StatUserComposeForm)   form;//   TODO   Auto-generated   method   stub String   validYear=sucForm.getValidYear(); String   pressCode=sucForm.getPressCode(); String   pressName=sucForm.getPressName(); String   districtCode=sucForm.getDistrictCode(); String   serviceId=sucForm.getServiceId(); String   readerClass=sucForm.getReaderClass(); String   issueNo=sucForm.getIssueNo(); String   proName=sucForm.getProName(); String   cityName=sucForm.getCityName(); String   countyName=sucForm.getCountyName(); service   =   (IStatUserComposeService)   this.getService(); sucForm.setValidYear(validYear); sucForm.setPressCode(pressCode); sucForm.setPressName(pressName); sucForm.setServiceId(serviceId); sucForm.setIssueNo(issueNo); sucForm.setProName(proName); sucForm.setCityName(cityName); sucForm.setCountyName(countyName); sucForm.setDistrictCode(districtCode); request.setAttribute("sucForm",   sucForm); List <? >   totalList=null; addMessage("message.common","发行量趋势分析检索完毕!"); //设置查询后的结果集 request.setAttribute("result",totalList); return   mapping.findForward("table"); } 变量pressName得到正确结果  

    最新回复(0)