用httpclient提交数据时碰到个问题:
这个好像不是值对的关系了,有个checked,三个值怎么处理呢?
后来查了下html spec,按它的说法,不是所有的form数据都会被提交上去,只有"successfull controls"才可以,也就是说,当checkbox为checked时,它的name/value才会被提交,否则在提交时将会忽略这项。
还有一点没解决就是好几个checkbox有相同名字时,并且全是"successful controls",那提交时怎么区分name/value呢?liuzg说需要通过js处理然后动态地修改name值使其不一样后再提交。8过httpcliet能执行js嘛? 留着问题。。。
2006-06-27
2006-06-14
类布署不到服务器上的问题
用myeclipse开发的时候,写了一个action类,却总也布署不上去,执行的时候老说找不到这个action的instance,后来偶然发现我写的类并没有编译成class文件从而布署,然后察看了一下buildpath,原来有一个jar系统找不到,所以在正确配置这个包前它不会编译任何添加进来的文件。
2006-06-01
2006-05-27
DWR是个好东西
DWR
如果你有个POJO写成下面的格式:
你需要通过javascript访问到这个方法并展示在页面中,容易么?DWR告诉你,相当容易:
Woo~ Cool~
下面讲一下具体实施办法:
下载一个dwr.jar放到WEB-INF/lib目录下,然后修改web.xml,添加个servlet:
不贴代码了,用blogger的编辑器编辑的时候有些麻烦,它自动处理代码,即使你不愿意它处理,看dwr上的getstart吧
然后再创建个dwr.xml放在web.xml同目录下,并把自己创建的类的信息写进来:
不贴代码了,用blogger的编辑器编辑的时候有些麻烦,它自动处理代码,即使你不愿意它处理,看dwr上的getstart吧
然后建立个testdwr.html文件:
把这几个script文件连接进来:
/dwr/dwr/interface/Demo.js
/dwr/dwr/engine.js
然后再写个javascript脚本函数:
然后随便找个地方调用getReply()就可以看到效果了,非常cool~
如果你有个POJO写成下面的格式:
public class DwrMagic
{
public String reply()
{
return "oh, dwr magic !";
}
}
你需要通过javascript访问到这个方法并展示在页面中,容易么?DWR告诉你,相当容易:
DwrMagic.reply(function(replycontent){alert(replycontent);}Woo~ Cool~
下面讲一下具体实施办法:
下载一个dwr.jar放到WEB-INF/lib目录下,然后修改web.xml,添加个servlet:
不贴代码了,用blogger的编辑器编辑的时候有些麻烦,它自动处理代码,即使你不愿意它处理,看dwr上的getstart吧
然后再创建个dwr.xml放在web.xml同目录下,并把自己创建的类的信息写进来:
不贴代码了,用blogger的编辑器编辑的时候有些麻烦,它自动处理代码,即使你不愿意它处理,看dwr上的getstart吧
然后建立个testdwr.html文件:
把这几个script文件连接进来:
/dwr/dwr/interface/Demo.js
/dwr/dwr/engine.js
然后再写个javascript脚本函数:
function getData(str)
{
alert(str);
}
function getReply()
{
Demo.reply(getData);
}
然后随便找个地方调用getReply()就可以看到效果了,非常cool~
2006-05-25
代用户与server交互
Cookie怎么保存
JDK里没有参考实现,只有一个CookieHandler,而且是全局的,也就是说在一个JVM内你只能代表一个用户,后来找到个JCookie,不过操作起来挺麻烦的,后来感觉好像还和IE有关联,因为我没开IE的时候它就运行出错,开着就一切OK =_=#!
最后找到一个很好的:HttpClient,是apache的,早找到就好了,T_T,挺好用的,而且还带了些sample,常用的功能基本都能展示出来,暂时先不贴代码....
JDK里没有参考实现,只有一个CookieHandler,而且是全局的,也就是说在一个JVM内你只能代表一个用户,后来找到个JCookie,不过操作起来挺麻烦的,后来感觉好像还和IE有关联,因为我没开IE的时候它就运行出错,开着就一切OK =_=#!
最后找到一个很好的:HttpClient,是apache的,早找到就好了,T_T,挺好用的,而且还带了些sample,常用的功能基本都能展示出来,暂时先不贴代码....
2006-05-24
建立ssl连接并通过BASIC认证
贴段代码了,没啥好说的哦
把用户名和密码改掉了,嘿。只要你注册一个blogger的账号就可以顺利获得结果 :)
还有,blogger的atom API在这
public void testHttpsConnection() throws Exception
{
URL url = new URL("https://www.blogger.com/atom");
X509TrustManager xtm = new X509TrustManager()
{
public void checkClientTrusted(X509Certificate chain[], String authType)throws CertificateException{}
public void checkServerTrusted(X509Certificate chain[], String authType)throws CertificateException{}
public X509Certificate[] getAcceptedIssuers()
{
X509Certificate[] cert = {};
return cert;
}
};
TrustManager mytm[] = {xtm};
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null,mytm, null );
SSLSocketFactory sf = ctx.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(sf);
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
String usernamePassword = "username" + ":" + "password";
String encoding = new BASE64Encoder().encode(usernamePassword.getBytes());
conn.setRequestProperty("Authorization", "BASIC " + encoding);
InputStream in = conn.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IoUtil.transfer(in, out);
System.out.println(new String(out.toByteArray()));
}
把用户名和密码改掉了,嘿。只要你注册一个blogger的账号就可以顺利获得结果 :)
还有,blogger的atom API在这
2006-05-23
从群里偷偷瞄来的,收藏下~
Re: SSLHandshakeException: could not find trusted certificate
Sep 2, 2002 6:40 AM (reply 1 of 12)
if you work in windows in control panel you have java plugin -
there is column certificates then you click on secure site and import public key.
in unix execute ControlPanel from your java direcotry and makes the same.
it could help.
l33t0n3
Posts:5
Registered: 9/3/02 Re: SSLHandshakeException: could not find trusted certificate
Sep 3, 2002 9:31 AM (reply 2 of 12)
There are two ways to fix your problem. The first is add the certificate(s) of the target site to your TrustStore.
In the JSSE, the TrustStore object is a Keystore file which contains the public key(s) and any Root keys for a server certificate. You can add the key to your truststore by using keytool. (read JSSE documentation http://java.sun.com/products/jsse/doc/guide/API_users_guide.html to learn more about keytool):
In order to do this you will need to get the servers public (not private) key and any root certificates and then use the keytool.
Unfortunately, most of the time this is way too much of a pain in the butt to do for every ssl connection. For this reason, you can actually create your own TrustManager implementaiton and assign it to the SSLSocketFactory. The SSLSocketFactory can either be used by you directly, or you can let the java.net.URL connection factory handle the fetching and reading of sockets for you. I highly recommend using java.net.URL because it will load the https handler and you won't have to worry about writing the http requests properly.
First, you must create an implementation of the TrustManager factory. I recommend that for your first go you just trust everything (i.e. the isServerTrusted(X509Certificate[] Servers) method should always return true).
Make sure you have specified your provider (system property or dynamically as shown (this is jdk1.3 w/ JSSE 1.0.3, with jdk 1.4 it s bit different)...
java.security.Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
get your ssl context...
ctx = SSLContext.getInstance("TLS");
create an array of 1 object containing your TrustManager...
TrustManager[] _trustm = {new your.BogusX509TrustManager()};
And then tell the context to init using your trust manager...
ctx.init(null, _trustm, null);
make that your default socket factory for ssl connections...
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
Now your SocketFactory (and TrustManager) will be used for any new https connection you open in this instance. Since you set isServerTrusted to always return true, you will trust all certificates. You can also go a bit farther and validate certificates and store certificates in your TrustStore...
Sep 2, 2002 6:40 AM (reply 1 of 12)
if you work in windows in control panel you have java plugin -
there is column certificates then you click on secure site and import public key.
in unix execute ControlPanel from your java direcotry and makes the same.
it could help.
l33t0n3
Posts:5
Registered: 9/3/02 Re: SSLHandshakeException: could not find trusted certificate
Sep 3, 2002 9:31 AM (reply 2 of 12)
There are two ways to fix your problem. The first is add the certificate(s) of the target site to your TrustStore.
In the JSSE, the TrustStore object is a Keystore file which contains the public key(s) and any Root keys for a server certificate. You can add the key to your truststore by using keytool. (read JSSE documentation http://java.sun.com/products/jsse/doc/guide/API_users_guide.html to learn more about keytool):
In order to do this you will need to get the servers public (not private) key and any root certificates and then use the keytool.
Unfortunately, most of the time this is way too much of a pain in the butt to do for every ssl connection. For this reason, you can actually create your own TrustManager implementaiton and assign it to the SSLSocketFactory. The SSLSocketFactory can either be used by you directly, or you can let the java.net.URL connection factory handle the fetching and reading of sockets for you. I highly recommend using java.net.URL because it will load the https handler and you won't have to worry about writing the http requests properly.
First, you must create an implementation of the TrustManager factory. I recommend that for your first go you just trust everything (i.e. the isServerTrusted(X509Certificate[] Servers) method should always return true).
Make sure you have specified your provider (system property or dynamically as shown (this is jdk1.3 w/ JSSE 1.0.3, with jdk 1.4 it s bit different)...
java.security.Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
get your ssl context...
ctx = SSLContext.getInstance("TLS");
create an array of 1 object containing your TrustManager...
TrustManager[] _trustm = {new your.BogusX509TrustManager()};
And then tell the context to init using your trust manager...
ctx.init(null, _trustm, null);
make that your default socket factory for ssl connections...
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
Now your SocketFactory (and TrustManager) will be used for any new https connection you open in this instance. Since you set isServerTrusted to always return true, you will trust all certificates. You can also go a bit farther and validate certificates and store certificates in your TrustStore...
Subscribe to:
Posts (Atom)