File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Help needed with DOJO and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Help needed with DOJO and JSP" Watch "Help needed with DOJO and JSP" New topic

Help needed with DOJO and JSP

Anthony Taylor

Joined: May 04, 2006
Posts: 26
I have been trying to implement dojo but I am receiving errors when I retrieve the response. I dont see where the problem lies. Does anyone have any examples of retrieving xml from a jsf page. The type parameter seems to have a value of 'error'. Also, could somene point me in the direction of some good examples of using jsp with dojo? Here is my code:


<title>Dojo: Hello World!</title>

<!-- SECTION 1 -->
<script type="text/javascript" src="js/dojo/dojo.js"></script>
<script type="text/javascript" src="js/dojo/kstools.js"></script>
<script type="text/javascript">

// Load Dojo's code relating to widget managing functions

// Load Dojo's code relating to the Button widget

function helloPressed()
// Don't forget to replace the value for 'url' with
// the value of appropriate file for your server
// (i.e. 'HelloWorldResponsePOST.asp') for an ASP server{
url: 'HelloWorldResponseGET.jsp',
handler: helloCallback,
formNode: dojo.byId('myForm'),
mimetype: 'text/xml'

function init()
var helloButton = dojo.widget.byId('helloButton');
dojo.event.connect(helloButton, 'onClick', 'helloPressed')


function helloCallback(type, data, evt)
if (type == 'error')
alert('Error when retrieving data from the server!');
var root = data.getElementsByTagName('ksdata').item(0);
var child = root.childNodes.item(0);
dojo.byId('textdata').innerHTML = child.childNodes.item(0);


<button dojoType="Button" widgetId="helloButton" toggle="explode" toggleDuration="250">Hello World!</button>
<form id="myForm" method="POST">
Please enter your name: <input type="text" name="name">
<select dojoType="combobox">
<option value="foo">foo</option>
<option value="bar">bar</option>
<option value="baz">baz</option>
<option value="thud">thud</option>
your response is <span id="textdata"></span>


' HelloWorldResponseGET.jsp
' --------
' Print the name that is passed in the
' 'name' GET parameter in a sentence

"<ksdata>" +
"<message>" +
"<type>error</type>" +
"<text>You entered an invalid username.</text>" +
"</message>" +
"<values>" +
"<value>" +
"<name>Control1</name>" +
"<text>Text1</text>" +
"</value>" +
"<value>" +
"<name>Control2</name>" +
"<text>Text2</text>" +
"</value>" +
"<value>" +
"<name>Control3</name>" +
"<text>Text3</text>" +
"</value>" +
"<value>" +
"<name>Control4</name>" +
"<text>Text4</text>" +
"</value>" +
"</values>" +
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

What is DOJO?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Anthony Taylor

Joined: May 04, 2006
Posts: 26
dojo is a framework for doing ajax and widgets.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

This doesn't seem to be JSP related to me.

We have
  • HTML/Javascript
  • Java Server Faces
  • Other Frameworks

  • I'm guessing the HTML/Javascript forum will be your best bet for this question. Let me know where you would like it moved.
    Also, a readonly copy of this thread will stay in this forum.
    [ January 07, 2007: Message edited by: Ben Souther ]
    Bear Bibeault
    Author and ninkuma

    Joined: Jan 10, 2002
    Posts: 63873

    The HTML forum would be most appropriate. Thusly moved.

    [Asking smart questions] [About Bear] [Books by Bear]
    Joel Jorgensen

    Joined: Oct 13, 2006
    Posts: 22
    Not sure whether this will help with your larger problem of getting an error when you make the request, but most of the things that I have read about Dojo say that you should have your dojo.require() statements all in a separate block of script from the actual functions, like this:

    As far as debugging the error that you're getting, nothing is really jumping out at me as being incorrect about your code. This is probably a silly suggestion on my part, but are you certain that the Ajax call is getting to the proper JSP on the server? If so, then I'd recommend putting some extra code in the JSP to see what exactly it is sending back, and putting some code in your handler method in the Javascript to actually see what is in the type, data, and evt variables (especially type and data). This might help give you some clues as to what's going wrong and where.
    [ January 08, 2007: Message edited by: Joel Jorgensen ]

    Go is to the fountain.
    I agree. Here's the link:
    subject: Help needed with DOJO and JSP
    It's not a secret anymore!