2013-11-01 4 views
0

Liferay 서버에서 파일을 다운로드하기 위해 Java 코드를 작성하려고합니다. 나는이 예제를 찾았지만 대상 URL 삽입 할 위치를 모르겠어요 : 당신은 내가 요청을 만들려면 어떻게해야합니까이 클래스는 그래서 HttpServletRequest을 필요로보고 내 URL에 연결다시피Java의 Liferay 서버에서 파일 다운로드

static Object setRequest(){ 

    static String getURL(HttpServletRequest req) { 

     String scheme = req.getScheme();    // http 
     String serverName = req.getServerName();  // hostname.com 
     int serverPort = req.getServerPort();  // 80 
     String contextPath = req.getContextPath(); // /mywebapp 
     String servletPath = req.getServletPath(); // /servlet/MyServlet 
     String pathInfo = req.getPathInfo();   // /a/b;c=123 
     String queryString = req.getQueryString(); // d=789 

     // Reconstruct original requesting URL 
     StringBuffer url = new StringBuffer(); 
     url.append(scheme).append("://").append(serverName); 

     if ((serverPort != 80) && (serverPort != 443)) { 
      url.append(":").append(serverPort); 
     } 

     url.append(contextPath).append(servletPath); 

     if (pathInfo != null) { 
      url.append(pathInfo); 
     } 
     if (queryString != null) { 
      url.append("?").append(queryString); 
     } 
     return url.toString(); 
    } 
} 

를?

답변

0
String urlname = "";//You set your url path for the file 
URL url = new URL(urlname); 
HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
if (con.getResponseCode() == 200) { 
    InputStream stream = con.getInputStream(); 
    // now you can read the read the data 
} 
+0

감사하지만 어디에서 읽을 필요가있는 URL을 포함할까요? getRequestURL()은 url을 인수로 사용합니까? – user2940994

+0

다시 한 번 감사드립니다.하지만 요점을 놓치고 있습니다. 서버 사이트 (다운로드하려는 서버)에 lifeRay가 있습니다.이 직접 연결 방법이 작동하지 않습니다. – user2940994

관련 문제