Feeds

Streamline your search with Yahoo! Web Services and AJAX

Google - not the only fruit

  • alert
  • submit to reddit

Top three mobile application threats

The XML response returned by the Contextual Web Search service conforms to the XML Schema http://search.yahooapis.com/WebSearchService/V1/WebSearchResponse.xsd. In the input.jsp add a form containing fields for application ID, query, results, and context. The form may be submitted using GET or POST, but to use a context with many search terms use the POST method.

Send an AJAX request

To send an AJAX request we shall use a proxy servlet that routes the XMLHttpRequest from the browser to the Yahoo! Web Service. If an XMLHttpRequest is sent without a proxy servlet the XMLHttpRequest does not get sent and an error, such as the one below, is generated.

Error: uncaught exception: Permission denied to call method XMLHttpRequest.open

A proxy servlet may be developed or the HTTP proxy servlet may be used. Download httpProxyPackage.jar. Add the proxy servlet JAR file to the Libraries of the WebSearchWebService project. To the web.xml file add <servlet/> and <servlet-mapping/> elements for the proxy servlet.

<servlet>
        <servlet-name>HttpProxy</servlet-name>
        <servlet-class>com.jsos.httpproxy.HttpProxyServlet</servlet-class>
        <init-param>
            <param-name>host</param-name>
            <param-value>http://search.yahooapis.com/WebSearchService/V1/contextSearch</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>HttpProxy</servlet-name>
        <url-pattern>/servlet/yahoo</url-pattern>
    </servlet-mapping>

The procedure to send an AJAX request is as follows:

  1. Initiate an AJAX request from an HTML event such as a button click
  2. Create a XMLHttpRequest object
  3. Open a connection with the web service URL using the open() method of the XMLHttpRequest object
  4. Register a callback function to be invoked when the Ajax request is complete
  5. Send the AJAX request with the send() method
  6. Update the web page with the web service response

In the input.jsp, to the input element of type button add a onclick event handler to invoke a JavaScript function displaySearchResults(). In the displaySearchResults function create an XMLHttpRequest object. XMLHttpRequest is supported as a native object in some browsers such as Netscape 6 or later and Internet Explorer 7 and as an ActiveXObject in other browsers such as IE 6.

Specify the proxy servlet URL to which an AJAX request is to be sent. Obtain the values for query, results and context request parameters from the input form. Open an XMLHttpRequest request using the open() method. Register a callback function that is to be invoked when the request state changes using the onreadystatechange property of the XMLHttpRequest object. Send the XMLHttpRequest request using the send() method. In the callback function check if the request is complete and invoke the JavaScript function processResponse() to update the web page with the Web Service response. The complete input.jsp is available in this zipped folder.

Integrated JavaScript editor

JDeveloper 11g includes an integrated JavaScript editor for creating JavaScript. In the previous section we added the JavaScript directly to the JSP, but the JavaScript may also be created in a separate .js file and the .js file added to the JSP using the <script/> tag. Create a JavaScript file by selecting File>New and in the New Gallery window Web Tier>HTML>JavaScript File. Copy the JavaScript from the input.jsp JSP to the JavaScript file and delete the JavaScript from the JSP.

Seven Steps to Software Security

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Captain Kirk sets phaser to SLAUGHTER after trying new Facebook app
William Shatner less-than-impressed by Zuck's celebrity-only app
Apple fanbois SCREAM as update BRICKS their Macbook Airs
Ragegasm spills over as firmware upgrade kills machines
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
Mozilla fixes CRITICAL security holes in Firefox, urges v31 upgrade
Misc memory hazards 'could be exploited' - and guess what, one's a Javascript vuln
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
prev story

Whitepapers

Top three mobile application threats
Prevent sensitive data leakage over insecure channels or stolen mobile devices.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
Build a business case: developing custom apps
Learn how to maximize the value of custom applications by accelerating and simplifying their development.