applet 트리거 Servlet【2】

1918 단어 자바
public class LogConnectionManager {

	private static URLConnection conn = null;
		
	public static URLConnection getURLConnection() {
		try {
			URL url = new URL("http://127.0.0.1:8888/appletserver/logServlet");			
			conn = url.openConnection();
			if(urlConn instanceof HttpURLConnection) {  
				 //         "POST",   GET
                			((HttpURLConnection)urlConn).setRequestMethod("POST");
          			  } 
			conn .setDoOutput(true);
			conn .setUseCaches(false);
			conn .setRequestProperty("Content-Type", "application/x-java-serialized-object");
			return conn;
		} catch (Exception e) {
			//log.debug("URL connection failed ", e);
			return null;
		} 
  }

public static void sendMsg(String content){
		URLConnection conn = getURLConnection();
		InputStream input = null;
		InputStreamReader reader = null;
		BufferedReader buffer = null;
		if (null == conn) {
			return;
		}
		try {
			OutputStream output = conn.getOutputStream();   
			content = URLEncoder.encode(content, "UTF-8");
			output.write(content.getBytes("UTF-8"));   
			output.flush();   
			output.close();  
			input = conn.getInputStream();   
			reader = new InputStreamReader(input);   
			buffer = new BufferedReader(reader);   
			StringBuffer sb = new StringBuffer();   
			String temp = null;   
			while((temp = buffer.readLine()) != null) {   
				sb.append(temp);   
			} 
			   
			System.out.println(sb.toString()); 
		} catch (Exception e) {
			log.debug(e);
		} finally {
			buffer.close();   
			reader.close();   
			input.close();
		} 
	}
}

좋은 웹페이지 즐겨찾기