请教一些关于ubuntu server9.10环境下的java配置的一些问题.

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
风远尘
帖子: 11
注册时间: 2008-02-12 23:55

请教一些关于ubuntu server9.10环境下的java配置的一些问题.

#1

帖子 风远尘 » 2011-01-08 10:04

我有两台服务器,一台安装的是ubuntu server 9.10 64位, 暂称A

一台安装的是ubuntu server 10.10 64位 ,暂称B,我就 sudo apt-get install openjdk-6-jdk

我用httpclient写了一些自动登陆https的网站的代码,

然后放到 B上面测试,一切正常.

然后我想放到 A 上面正式运行,一开始出现的问题是 中文全部变成 问号, 后来折腾了两天才发现 是因为 file.encoding参数引起的.

问题1: 我想知道在哪里配置jvm的参数, 我现在是在启动是时候加上 file.encoding参数 java -Dfile.encoding=UTF-8 test

问题2:

代码: 全选

public class test {
    public static void main(String[] args) throws ClientProtocolException, IOException{
        System.out.println(System.getProperty("file.encoding"));
    }
}
以上是我的java 代码, 在A上面输出结果是ANSI_X3.4-1968, 在B上面输出是UTF-8, 在A及B上面执行loacle -a输出结果完全一样,如何把A的也改成UTF-8??

问题3: 是关于httplicent

代码: 全选

public class ClientCustomSSL {

    public final static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();

        KeyStore trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());        
        FileInputStream instream = new FileInputStream(new File(System.getProperty("user.dir")+"/my.trustst")); 
        try {
            trustStore.load(instream, "nopassword".toCharArray());
        } finally {
            instream.close();
        }
        
        SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
        Scheme sch = new Scheme("https", socketFactory, 443);
        httpclient.getConnectionManager().getSchemeRegistry().register(sch);

        HttpGet httpget = new HttpGet("https://www.95599.cn/");

        System.out.println("executing request" + httpget.getRequestLine());
        
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
        }
        if (entity != null) {
            entity.consumeContent();
        }

        // When HttpClient instance is no longer needed, 
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();        
    }

}
以上代码我完全照抄httpclient的示例代码, 我只是把网址换了, 但https://www.95599.cn也不是我最终想要登陆的网址,
同样的代码我在B下面执行,我在我开发的电脑上执行都没有问题,但上传到A上面后就提示,求解

代码: 全选

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
        at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352)
        at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
        at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:399)
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
        at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
        at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
头像
astolia
论坛版主
帖子: 6450
注册时间: 2008-09-18 13:11

Re: 请教一些关于ubuntu server9.10环境下的java配置的一些问题.

#2

帖子 astolia » 2011-01-08 18:09

1、在~/.profile里写
export _JAVA_OPTIONS='-Dfile.encoding=UTF-8'

2、locale -a只是列出可用的语言环境,locale才是列出当前所用的语言环境

3、https://www.95599.cn/没有SSL证书或证书错误。出错的机器上把证书拉黑了
回复