헤르메스 LIFE

[HttpURLConnection] jsp 파일의 실행 본문

Core Java

[HttpURLConnection] jsp 파일의 실행

헤르메스의날개 2020. 12. 17. 00:42
728x90

 

public String executeJSP(String urlstr) {
  URL url = null;
  BufferedReader in = null;
  URLConnection con = null;
  String returnMsg = "";

  try {
   url = new URL(urlstr);
   con = url.openConnection();

   con.connect();
   System.out.println("++++++++Start+++++++++++");
   System.out.println("getContentType()  : " + con.getContentType() );
   System.out.println("getContentLength() : " + con.getContentLength());
   System.out.println("getUseCaches() : " + con.getUseCaches());
   System.out.println("getContent() : " + con.getContent());
   System.out.println("getRequestMethod() : " + ((HttpURLConnection)con).getRequestMethod());
   System.out.println("getResponseCode() : " + ((HttpURLConnection)con).getResponseCode());
   System.out.println("getResponseMessage() : " + ((HttpURLConnection)con).getResponseMessage());
   System.out.println(con);
   System.out.println("++++++++++++++++++++++");

   returnMsg = ((HttpURLConnection)con).getResponseMessage();

   in = new BufferedReader(new InputStreamReader(con.getInputStream()));

   String msg = null;
   while((msg = in.readLine()) != null) {
//    returnMsg += msg ;
   }
  } catch (MalformedURLException malformedurlexception) {
   returnMsg = "URL Error";
  } catch (IOException ioexception) {
   returnMsg = "IO Error";
  } finally {
   try {
    if(in != null) in.close();
   } catch(Exception ex3) {
    System.out.println(ex3.toString());
   }
  }

  return returnMsg;
 }

 

728x90

'Core Java' 카테고리의 다른 글

[Source] DOM4j Modify XMLDemo  (0) 2020.12.20
[Source] XPatharserDemo  (0) 2020.12.20
외부프로그램 실행시키기  (0) 2020.12.17
Thread 를 이용한 데몬 프로그램  (0) 2020.12.17
BigDecimal타입의 사칙연산  (0) 2020.12.17