Trevar Pearce

Greenhorn
+ Follow
since Jul 13, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Trevar Pearce

Hi,

Thanks for the reply Merrill. I'm still unclear on how to do something though.

I want to populate an html select menu in the struts framework with query results from an Oracle database. The problem is that I want to do it as soon as the web-app starts. Is there a way to accomplish this?

Thanks, Trevar
17 years ago
Hi,

I'm attempting to build a struts 1.1 form and I need to generate the options in a select menu from the database. The application will be only one jsp with two sections, the form and the results. I have written a database access class and a bean to store the arraylist of results. I am stumbling, however, on how exactly to call this class from the jsp. Is there a way to do this without going through an action class (which would require some sort of page refresh, which I'd like to avoid)? Can I use JavaScript to call the class (my first thought was using an onload event to call it, but I'm not clear on whether it's even possible to call a java class from javascript)?

Thanks,

Trevar
17 years ago
So, I've in fact more or less solved the problem. The solution confuses me however, so if anyone can help me understand, I would very much appreciate it.

My jsp forwards to an action class which calls a class that does the database access. The database access class returns the result to the action class. The action class populates a bean with the results and sets a request attribute with the bean. Finally it forwards back to the jsp, which displays the results from the bean. As you can tell, it's a tiny web-app at this point, but I believe it is structured properly (if you have different information about where the db access should happen, please let me know, I really want this app to be structured to the standards).

The thing that I got hung up on was accessing the application scope attributes (from the ServletContext) in the database access method. I'll post it here:



As I said, I'm calling this class and its one method rather than forwarding to it. As such, I think it's not being passed the ServletContext unless I do it explicitly(as I do). This is what confuses me. I assumed that because the ServletContext was application scope that it would automatically be available in any class I called in my web-app. I guess that was a poor assumption. Can anyone explain what I'm missing here? There's some bit of theory that hasn't gotten through to me and I'd really appreciate it if someone could explain briefly.

Thanks, Trevar
17 years ago
Hi again, so I've narrowed it down a bit. Looks like the getDataSource is calling Action.class and it's stumbling on the following line:



I've commented all my db access code out and just entered that (and imported javax.servlet.ServletContext) and I get the same NullPointerException. Anybody know what's going on here?

Thanks, Trevar
17 years ago
Hi, thanks for the reply. I've implemented the code but unfortunately it's still giving me the java.lang.NullPointerException

When I remove the try/catch block from the database access action class, it produces this:



It's thus still the DataSource line that's breaking. Any ideas?
17 years ago
Hi, I'm using Struts 1.1 and Oracle 10g and attempting to establish a connection between the two. I have successfully done so by hard-coding the datasource info in my action class but am running into a problem when placing that info in the struts-config.xml. Here's the data-source entry:



I call it with this:



I have determined that it is stumbling on the DataSource line, giving me a java.lang.NullPointerException. If you can see what's going wrong with the code, please let me know.

Thanks
17 years ago