Ajax

Issues and Questions related to running Apache Tomcat on z/OS
Post Reply
jriemer
Posts: 25
Joined: Thu Jul 06, 2006 11:15 am

Ajax

Post by jriemer » Mon Jun 06, 2011 3:39 pm

Anybody have a successful Ajax implementation under z/OS Tomcat? No reason it shouldn't work; however, I'm unable to this point to successfully trigger a Tomcat servlet out of an Ajax Javascript function in a .jsp. Just curious.

dovetail
Site Admin
Posts: 1907
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail » Mon Jun 06, 2011 3:53 pm

It has worked fine for us in the past. Nothing special to do on the server, but it would depend on whether you are using some kind of server-side Ajax framework. Calling Java servlets from client javascript should be no problem.

jriemer
Posts: 25
Joined: Thu Jul 06, 2006 11:15 am

Ajax

Post by jriemer » Mon Jun 06, 2011 5:10 pm

Thanks. Do you use either of the following formats:

1. ajaxRequest.open("POST", "/servlet/servletname", true);
2. ajaxRequest.open("POST", "http://192.168.50.51:8080/servlet/servletname", true);

Neither seems to work for me.

dovetail
Site Admin
Posts: 1907
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail » Mon Jun 06, 2011 5:16 pm

No sorry. I'm not sure what Ajax client side javascript framework you are using. We have used Dojo in the past, but it really shouldn't matter.


Have your written Ajax clients for *any* Tomcat container? Try getting it working first to Tomcat on your desktop. If it works there, it should work when the server is on z/OS - unless your client-side framework requires a server side Java framework that isn't installed on your z/OS instance.

jriemer
Posts: 25
Joined: Thu Jul 06, 2006 11:15 am

Ajax

Post by jriemer » Mon Jun 06, 2011 7:31 pm

Would you be able to provide one of your (simpler) working examples?

dovetail
Site Admin
Posts: 1907
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail » Tue Jun 07, 2011 10:21 am

Sorry, unfortunately it was done as work for hire contract.

Try a simple Dojo example to a local Tomcat running on your desktop first, and then move the app to z/OS.

dovetail
Site Admin
Posts: 1907
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail » Tue Jun 07, 2011 12:23 pm

Sorry, I did find an example, from the "JZOS Cookbook":
http://www.alphaworks.ibm.com/tech/zosj ... k/download

The example web app in this book has a Catalog Search web service that is front-ended with a Flex (Flash) application. But following is an example of a small DoJo client that implements a "live" dataset list picker combo-box thingy.

Code: Select all

<html>
  <head>
    <title>z/OS DSN Picker</title>
      <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dijit/themes/tundra/tundra.css"/>
      <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" djConfig="parseOnLoad:true, isDebug: true" type="text/javascript"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dijit/dijit.js" djConfig="parseOnLoad:true, isDebug: true" type="text/javascript"></script>
      <script type="text/javascript">
          dojo.require("dijit.form.ComboBox");
          dojo.require("dojo.data.ItemFileReadStore");
      </script>
      <script type="text/javascript">
          function doCbSearch(e) {
            var fkey = dijit.byId("cbDsn").attr('displayedValue') + e.keyChar;
            //console.debug("fkey=" + fkey + " key=" + e.charOrCode + "," + e.keyChar);
            if ((e.keyChar == "") && (e.charOrCode != dojo.keys.BACKSPACE)) {
              return; //Don't query unless a character or backspace has been entered
            }
            dijit.byId("cbDsn").store = new dojo.data.ItemFileReadStore({data: {items: []}});
            var parms = new Object();
            parms.filterkey = (e.charOrCode == dojo.keys.BACKSPACE) ? fkey.substring(0,fkey.length-1) : fkey;
            if (fkey.indexOf(".") == -1) {
              return; //Don't search until a complete HLQ is entered
            }
            parms.filterkey += (fkey[fkey.length-1] == ".") ? "**" : "*.**";
            parms.workarealength = 1024;
    
            dojo.xhrPost({
              url: "api/catalogsearch",
              load: handleResponse,
              error: function(data, ioArgs) {alert("Error: "+data)},
              content: parms,
              handleAs: 'xml'
            });
        }
  
        function handleResponse(data, ioArgs) {
          var entries = new Array();
          for (i=0; i<10; i++) { // take first 10 entries
            var entry = data.getElementsByTagName("entry")[i];
            if (entry == null) {
              break;
            }
            entries[i] =  {'dsn':dojo.attr(entry,"name")};
          }
          dijit.byId("cbDsn").store = new dojo.data.ItemFileReadStore({data: {items: entries}});
        }
      </script>    
  </head>

  <body class="tundra">
  DSN Picker: <input dojoType="dijit.form.ComboBox"
                     id="cbDsn" 
                     searchAttr="dsn" 
                     onKeyPress="doCbSearch" 
                     searchDelay="300"
                     style="width: 44em"
                     highlightMatch="none"
                     autoComplete="false"/>
  </body>
</html>

jriemer
Posts: 25
Joined: Thu Jul 06, 2006 11:15 am

Ajax

Post by jriemer » Tue Jun 07, 2011 9:21 pm

Thanks very much.

Post Reply