2 linkangjie linkangjie 于 2013.12.24 17:41 提问

接口压缩解压编码解码变成乱码

public class SSSS extends HttpServlet {

//str="杀神"
public String zip_Base642(String str) {
    if (str == null)
        return null;
    byte[] compressed;
    ByteArrayOutputStream out = null;
    ZipOutputStream zout = null;
    String compressedStr = null;
    try {
        out = new ByteArrayOutputStream();
        zout = new ZipOutputStream(out);
        zout.putNextEntry(new ZipEntry("0"));
        zout.write(str.getBytes());
        zout.closeEntry();
        String abc = Base64.encode(out.toByteArray());
        System.out.println("abc = " + abc);
        return abc;
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
SSSS ss = new SSSS();
out.println(ss.zip_Base642("杀神"));
out.flush();
out.close();
}
public static void main(String[] args) {
SSSS ss = new SSSS();
String s1 = ss.zip_Base642("杀神");
System.out.println("s1 = " + s1);
}
}

访问方式1:IEmService ii = new IEmServiceImpl();

结果:UEsDBBQACAAIANeLmEMAAAAAAAAAAAAAAAABAAAAMHs2t+H50nkAUEsHCGw8et0IAAAABgAAAA==

访问方式2:http://localhost:8888/SSSS

结果:UEsDBBQACAAIAPKLmEMAAAAAAAAAAAAAAAABAAAAMDu58eRHAFBLBwg6RB8+BgAAAAQAAAA=

同样的代码 为什么不一样的结果呢? 哪位朋友帮我解决下

接口压缩解压编码解码变成乱码,只是在tomcat中使用没问题,只是在安卓中使用也没问题,只是直接在本地new实例也没问题,但是交叉使用就有问题了

我需要在tomcat中访问程序得到压缩的编码,然后在安卓中解压解码得到结果,但是现在结果是不对的

Csdn user default icon
上传中...
上传图片
插入图片