当前位置:编程学习 > JAVA >>

Struts2的乱码问题

这是JSP页面

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
  <head>
    <title>按客户地址查询客户</title>
    <style type="text/css">
     td{
     font-size: 12px;
     }
    </style>
  </head>
  
  <body>
<table border="0" width="95%">
<tr align="center">
<td><h1>按客户地址查询客户</h1></td>
</tr>
<tr align="center">
<td>
<s:form action="findCustomerAddress" method="post">
<table border="0">
<tr>
<td>客户地址</td>
<td><s:textfield name="customer.address"/><br/></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交">
<input type="reset" value="重置">
</td>
</tr>
</table>
</s:form>
</td>
</tr>
</table>
  </body>
</html>


这是配置文件

<?xml version="1.0" encoding="gb2312" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">


   
<struts>
<constant name="struts.i18n.encoding" value="gb2312"/>
 <package name="default" namespace="/" extends="struts-default">
       <!-- Customer 配置 -->
        <action name="add" method="addCustomer" class="com.quote.action.customer.CustomerAction">
            <result name="success">
               /success.jsp
            </result>
        </action>
        
      <action name="findAll" class="com.quote.action.customer.CustomerFindAll">
            <result name="success">
               /page/customerdeal/CustomerAll.jsp
            </result>
        </action>
        
        <action name="findCustomerCode" method="FindCustomerCode" class="com.quote.action.customer.CustomerAction">
            <result name="success">
               /page/customerdeal/CustomerfindCode.jsp
            </result>
        </action>
        
        
         <action name="findCustomerName" method="FindCustomerName" class="com.quote.action.customer.CustomerAction">
            <result name="success">
               /page/customerdeal/CustomerfindCode.jsp
            </result>
        </action>
          <action name="findCustomerPhone" method="FindCustomerPhone" class="com.quote.action.customer.CustomerAction">
            <result name="success">
               /page/customerdeal/CustomerfindCode.jsp
            </result>
        </action>
         <action name="findCustomerOther" method="FindCustomerOther" class="com.quote.action.customer.CustomerAction">
            <result name="success">
               /page/customerdeal/CustomerfindCode.jsp
            </result>
        </action>
        
        
        <action name="findCustomerAddress" method="FindCustomerAddress" class="com.quote.action.customer.CustomerAction">
            <result name="success">
               /page/customerdeal/CustomerfindCode.jsp
            </result>
        </action>
        
        
        <action name="findCustomerRelationman" method="FindCustomerRelationman" class="com.quote.action.customer.CustomerAction">
            <result name="success">
               /page/customerdeal/CustomerfindCode.jsp
            </result>
        </action>
        
          <action name="deleteCustomer" method="Customerdelete" class="com.quote.action.customer.CustomerAction">
            <result name="success">
              /success.jsp
            </result>
        </action>
        
        
        <action name="updatePCustomer" method="UpdatePCustomer" class="com.quote.action.customer.CustomerAction">
            <result name="success">
             /page/customerdeal/CustomerUpdate.jsp
            </result>
        </action>
        
          <action name="updateCustomer" method="UpdateCustomerAction" class="com.quote.action.customer.CustomerAction">
            <result name="success">
              /success.jsp
            </result>
        </action>
        
         <!-- Product 配置 -->
        <action name="addProduct" method="AddPrroduct" class="com.quote.action.product.ProductAction">
            <result name="success">
             /page/productdeal/success.jsp
            </result>
        </action>
        
        <action name="findProductall" method="FindProductAll" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/ProductfindAll.jsp
            </result>
        </action>
        
          <action name="findId" method="FindProductId" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/Productfind.jsp
            </result>
        </action>
        
        <action name="findProductowner" method="FindProductowner" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/Productfind.jsp
            </result>
        </action>
        <action name="findProductname" method="FindProductname" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/Productfind.jsp
            </result>
        </action>
        <action name="findProductcode" method="FindProductcode" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/Productfind.jsp
            </result>
        </action>
        <action name="findProducingarea" method="FindProducingarea" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/Productfind.jsp
            </result>
        </action>
        <action name="findProductOther" method="FindProductOther" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/Productfind.jsp
            </result>
        </action>
        
         <action name="findProducttypecode" method="FindProducttypecode" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/Productfind.jsp
            </result>
        </action>
        
         <action name="deleteProduct" method="deleteProduct" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/success.jsp
            </result>
        </action>
        
        <action name="updatePProduct" method="updatePProduct" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/ProductUpdate.jsp
            </result>
        </action>
        <action name="updateProduct" method="updateProduct" class="com.quote.action.product.ProductAction">
            <result name="success">
              /page/productdeal/success.jsp
            </result>
        </action>
    </package>
</struts>


这是action

package com.quote.action.customer;

import java.util.Map;

import org.springframework.web.struts.ActionSupport;

import com.opensymphony.xwork2.ActionContext;
import com.quote.Service.CustomerService;
import com.quote.bean.Customer;
import com.quote.common.util.EncodingFilter;

public class CustomerAction extends ActionSupport{

private Customer customer;
private CustomerService customerService;


public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public CustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
}

@SuppressWarnings("unchecked")
public String FindCustomerAddress()throws Exception{

   System.out.println(customer.getAddress());
try {
Map request=(Map) ActionContext.getContext().get("request");

request.put("list", this.customerService.findAddress(customer.getAddress()));

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return "success";
}

}
}


打印乱码 啊 

怎么回事 各位大侠
--------------------编程问答--------------------
解决
--------------------编程问答-------------------- 我解决不了   我 struts  里面也有配置 啊  --------------------编程问答-------------------- 编码都设成试试GBK --------------------编程问答-------------------- 。。。。。 --------------------编程问答-------------------- 你的web.xml中什么版本的Struts过滤器
如果是2.1需要加个编码的过滤器,或者配置成2.0的过滤器也行 --------------------编程问答-------------------- /page/customerdeal/CustomerfindCode.jsp
 楼主在这个页面中有没有设置Encoding的编码啊? --------------------编程问答--------------------
引用 5 楼 wangxf_8341 的回复:
你的web.xml中什么版本的Struts过滤器
如果是2.1需要加个编码的过滤器,或者配置成2.0的过滤器也行
   没有啊 怎么了 。 --------------------编程问答--------------------
引用 6 楼 zongquanliu 的回复:
/page/customerdeal/CustomerfindCode.jsp
 楼主在这个页面中有没有设置Encoding的编码啊?
 没有在页面里面是设置啊  --------------------编程问答-------------------- 所有能改编码的地方都统一改utf-8 --------------------编程问答--------------------
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
//pageEncoding="gb2312",这个地方应该改成pageEncoding="UTF-8"


试一试,不行再想别的办法 --------------------编程问答-------------------- 在web.xml中写个过滤 --------------------编程问答-------------------- struts2不是有个很牛x的编码过滤器 --------------------编程问答-------------------- 乱码问题无非是编码的原因,页面编码、struts的拦截器(国际化)! --------------------编程问答-------------------- 开发工具 设置的编码 跟你页面设置的 一样吗? --------------------编程问答-------------------- 各位大侠 开发工具和页面都设的编码都是一样的 。我也尝试都换成UTF-8 或gb2312都不行啊 
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,