File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Simple struts question - Use action to retrieve data from db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Simple struts question - Use action to retrieve data from db" Watch "Simple struts question - Use action to retrieve data from db" New topic
Author

Simple struts question - Use action to retrieve data from db

Ritchie Warsi
Greenhorn

Joined: Nov 02, 2004
Posts: 29
I'm a struts newb, so this might be quite easy. All the tutorials I've read or either more complex or they use the jsp itself to generate a list of data.

I want my action class to retrieve my data for me from the db and send in to the jsp page.

So far I've got this (which doesn't work ofcourse):
I wanna use the following method in my CustomerDAO.java:


My getAccountAction.java has:


And my struts-config has the following action mapping:


My simple jsp has:


So obviously I'm doing something wrong or forgetting something. Can anyone point me out what?
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
How is what you have not working? Are you getting an error? What error are you getting?
Ritchie Warsi
Greenhorn

Joined: Nov 02, 2004
Posts: 29
Allright, my tomcat error logging isn't configured well, so I'll give you what I get on screen. I'm rather unsure as to what action to call first (getAccountAction or accOptions - the first forwards to the second that calls on a jsp, this is where my data should be - sounds complicated but it's for Tiles).

When calling on getAccountAction i get:


And when calling on accOptions.do i get:


But is my approach correct?

[ December 20, 2004: Message edited by: Ritchie Warsi ]

[ December 20, 2004: Message edited by: Ritchie Warsi ]

[ December 20, 2004: Message edited by: Ritchie Warsi ]

[ December 21, 2004: Message edited by: Jason Menard ]
[ December 21, 2004: Message edited by: Jason Menard ]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
The general approach is fine, however your problem is in your DAO's method. The RuntimeException that you throw when you catch the HibernateException isn't halting the application flow, so when your JSP tries to execute, it can't find the customerList bean that it expects to be in request since your getCustomerList() method in the DAO never returned one. I'm not really that up on Hiberbate, so as to why exactly your DAO method doesn't work, you would be best having that question answered in the Object Relational Mapping forum.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I would also add that if you are having your DAOs throw RuntimeExceptions, then you would want to make sure that you set up Struts Exception Handling to deal with these. Otherwise, you probably shouldn't be throwing RuntimeExceptions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple struts question - Use action to retrieve data from db