2011-09-19 3 views
0

내가 프로젝트에서 일하고 있어요 내가 서비스에 추가하는 등 글로벌 날씨와 같은 일부 웹 서비스를 사용해야 시작하는 방법, 내가 지금 뭘하는지 어쨌든 http://www.webservicex.net/globalweather.asmx?WSDL내가 넷빈즈를 사용하고</p> <p>.. 넷빈즈, WSDL 및 JSP

를, 그래서 이것은이다 : 현재 나는 국가 이름으로 날씨 + 도시를 호출하는이 웹 서비스를 사용할 수 있습니다

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>Weather Finder</title> 
    </head> 
    <body> 
     <h1>Weather Test</h1> <%-- start web service invocation --%><hr/> 
    <% 
    try { 
    net.webservicex.GlobalWeather service = new net.webservicex.GlobalWeather(); 
    net.webservicex.GlobalWeatherSoap port = service.getGlobalWeatherSoap(); 
    java.lang.String countryName = "Australia"; 
    java.lang.String result = port.getCitiesByCountry(countryName); 
    out.println("Result = "+result); 
    } catch (Exception ex) { 
    } 
    %> 
    <%-- end web service invocation --%><hr/> 

     <%-- start web service invocation --%><hr/> 
    <% 
    try { 
    net.webservicex.GlobalWeather service = new net.webservicex.GlobalWeather(); 
    net.webservicex.GlobalWeatherSoap port = service.getGlobalWeatherSoap(); 
    java.lang.String cityName = "Melbourne"; 
    java.lang.String countryName = "Australia"; 
    java.lang.String result = port.getWeather(cityName, countryName); 
    out.println("Result = "+result); 
    } catch (Exception ex) {} 
    %> 
    <%-- end web service invocation --%><hr/> 

    </body> 
</html> 

반환 :

<!DOCTYPE html> 
    <html> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
      <title>Weather Finder</title> 
     </head> 
     <body> 
      <h1>Hello World!</h1> <hr/> 
     Result = <NewDataSet> 
     <Table> 
     <Country>Australia</Country> 
     <City>Archerfield Aerodrome</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Amberley Aerodrome</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Alice Springs Aerodrome</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Brisbane Airport M. O</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Coolangatta Airport Aws</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Cairns Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Charleville Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Gladstone</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Longreach Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Mount Isa Amo</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Mackay Mo</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Oakey Aerodrome</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Proserpine Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Rockhampton Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Broome Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Townsville Amo</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Weipa City</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Gove Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Tennant Creek Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Yulara Aws</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Albury Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Devonport East</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Goldstream Aws</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>East Sale Aerodrome</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Hobart Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Launceston Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Laverton Aerodrome</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Moorabbin Airport Aws</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Mount Gambier Aerodrome</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Mildura Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
     <City>Melbourne Airport</City> 
     </Table> 
     <Table> 
     <Country>Australia</Country> 
    <City>Macquarie Island</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Wynyard West</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Adelaide Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Albany Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Broken Hill Patton Street</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Ceduna Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Derby</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Darwin Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Bullsbrook Pearce Amo</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Edinburgh M. O.</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Forrest Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Geraldton Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Kalgoorlie Boulder Amo</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Kununurra Kununurra Aws</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Leigh Creek Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Learmonth Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Meekatharra Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Port Hedland Pardoo</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Parafield Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Belmont Perth Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Katherine Aerodrome</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Woomera Aerodrome</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Bankstown Airport Aws</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Canberra</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Coffs Harbour Mo</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Cooma</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Camden Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Dubbo</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Norfolk Island Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Nowra Ran Air Station</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Richmond Aus-Afb</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Sydney Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Tamworth Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Wagga Airport</City> 
    </Table> 
    <Table> 
    <Country>Australia</Country> 
    <City>Williamtown Aerodrome</City> 
    </Table> 
</NewDataSet> 


    <hr/> 

     <hr/> 
    Result = <?xml version="1.0" encoding="utf-16"?> 
<CurrentWeather> 
    <Location>Melbourne Airport, Australia (YMML) 37-40S 144-50E 141M</Location> 
    <Time>Sep 19, 2011 - 07:39 AM EDT/2011.09.19 1139 UTC</Time> 
    <Wind> from the WSW (240 degrees) at 29 MPH (25 KT):0</Wind> 
    <Visibility> greater than 7 mile(s):0</Visibility> 
    <SkyConditions> mostly cloudy</SkyConditions> 
    <Temperature> 57 F (14 C)</Temperature> 
    <DewPoint> 44 F (7 C)</DewPoint> 
    <RelativeHumidity> 62%</RelativeHumidity> 
    <Pressure> 29.53 in. Hg (1000 hPa)</Pressure> 
    <Status>Success</Status> 
</CurrentWeather> 


    <hr/> 

    </body> 
</html> 

어느 쪽이 위대한가?하지만 XML 정보를 Java 응용 프로그램으로 다시 가져와 어떻게 유용하게 사용할 수 있습니까?

예를 들어 날씨 결과를 배열과 같은 유용한 것으로 변경하는 방법은 무엇입니까? 또는 ArrayList 내 응용 프로그램에서 다른 곳으로 호출하십시오.

감사합니다.

+0

를 (그것을 운영 후 DOM 트리에 HTML을 구문 분석) 귀하의 경우에 적용 할 수 있습니다 JSP에서 스크립틀릿 사용하기 http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202 – Sean

+0

이 상황에서 어떻게 JSTL을 사용할 수 있습니까? – Moe

+0

나는 여기서 EL을 더 보길 권합니다. 표시하는 유일한 결과는 JSP를 표시하기 전에 요청 속성에 쉽게 배치 될 수있는 결과입니다. – Sean

답변

0

result XML을 웹 서비스 결과의 스키마 (http://java.sun.com/developer/technicalArticles/xml/mapping/ 참조)에 해당하는 의미있는 Java 객체로 쉽게 변환 (구문 분석)하여 응용 프로그램의 서비스로 전달할 수 있습니다. 그런 다음 당신 (당신)의 자바 객체 목록에서 원하는대로 작동하십시오.

+0

PHP 배경에서 왔습니다. 그냥 XML 문자열에서 간단한 정보를 얻으려면 사용자 정의 클래스를 구현해야한다고 생각하십니까? Java는 왜 그렇게 복잡합니까? 위에서 XML을 MyArray [ "Weather"]와 같은 배열로 변환 할 수있는 방법이 없습니까? – Moe