JavaServer Pages (JSP) and JSTL - Returning a value to JSP from a class

Hello all,

I found this really small footprint XML parser: http://www.javaworld.com/javaworld/javatips/jw-javatip128.html

It uses a very simple call:

DocHandler doc =new MyDocHandler();

QDParser.parse(doc,new FileReader("config.xml"));

Instead of reading a file, I'm actually using StringReader and sending it a string which contains a SOAP response. QDParser does all kinds of really smart things to figure out where starting and ending tags are, and then calls yet another function in a seperate .java file to do something with it once it's determined whether or not it's a tag, actual data, etc.

doc.text(sb.toString());

The DocHandler class then has a method to do something with the text:

publicvoid text(String text){

System.out.println("text: "+text);

}

This all works fine as a standalone Java app and everything prints out nicely to the screen. However what I really want is to be able to store the value of that text in a variable in my JSP page. Preferably, the variable name would just be the tag name, but I have no idea how to return all of those values back to JSP.

I already know my code is really inefficient and likely not the best way to write the program, but it's a very small scope application that just shows that what I'm trying to do is possible. Can somebody point me in the right direction?

Thanks!

[1883 byte] By [balfortha] at [2007-11-26 23:13:45]
# 1

The QDParser returns type void:

public static void parse(DocHandler doc,Reader r) throws Exception {

I decided to try to return the values in perhaps a string array or hashtable. However if I change it to return anything at all, even an int and return a number, it gives me an exception. I tried creating a new class that did absolutely nothing besides return an int or a string, and I get the same exception:

exception

javax.servlet.servlet Exception: qdxml.Reporter.getData()Ljava/util/Iterator;

...

root cause

java.lang.NoSuchMethodError: qdxml.Reporter.getData()Ljava/util/Iterator;

Whatever the method is that I call, if I change

void

to anything and have it return a value I get this NoSuchMethodError.

Anybody have any ideas?

balfortha at 2007-7-10 14:12:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Sorry to keep posting replies to myself :)

I don't know what the problem is, but I found a solution. If I run the debugger, the NoSuchMethodError goes away. Then I exit the debugger and then everything works great! But if I change the return type on any method, I have to re-run the debugger first or I will get the same error.

Neat.

balfortha at 2007-7-10 14:12:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Which IDE are you using? Maybe something went wrong in hot deploy or so, then you'll need to restart the webapp in the server.
BalusCa at 2007-7-10 14:12:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Sun Java Studio 8.1. Additionally, I've noticed a couple times now that I can make changes in some of the external classes to return different values, and I won't see the changes until I debug.
balfortha at 2007-7-10 14:12:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Even not after restarting the webapp in the webcontainer or restarting the server?
BalusCa at 2007-7-10 14:12:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...