Applet内部デバッグで使っています。
Appletからのログ出力はできないっぽいのでCGIに値を渡してログを出しています。
Getメソッドの場合
public void debug( String str ){
String _str = str;
String debug_url = “http://デバッグ用CGIのURL?str=”;
try {
URL _url = new URL( debug_url + _str );
HttpURLConnection urlconn = (HttpURLConnection)_url.openConnection();
urlconn.setRequestMethod(“GET”);
urlconn.setInstanceFollowRedirects(false);
urlconn.setRequestProperty(“Accept-Language”, “ja;q=0.7,en;q=0.3”);
urlconn.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlconn.getInputStream()));
while (true){
String line = reader.readLine();
if ( line == null ){
break;
}
}
reader.close();
urlconn.disconnect();
}
catch(Throwable e){
}finally{
try{
}catch(Exception e){}
}
}
Postメソッドの場合
public void debug( String str ){
String _str = str;
String debug_url = “http://デバッグ用CGIのURL?str=”;
try{
URL _url = new URL( debug_url );
HttpURLConnection conn = (HttpURLConnection)_url.openConnection();
conn.setUseCaches(false);
conn.setRequestMethod(“POST”); /* GET or POST */
conn.setDoOutput(true); /* GET:false / POST:true */
conn.connect();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
StringBuffer outBuf = new StringBuffer();
/* GET の場合は URL にくっつける。 */
outBuf.append(“&str=”).append(URLEncoder.encode(_str,”UTF-8″));
writer.write(outBuf.toString());
writer.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),”UTF-8″));
StringBuffer inBuf = new StringBuffer();
String line;
while((line = reader.readLine()) != null){
inBuf.append(line).append(‘\n’);
}
System.out.println(inBuf.toString());
reader.close();
conn.disconnect();
}catch(Exception ex){
ex.printStackTrace();
}
}