Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple struts question - Use action to retrieve data from db

 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is what you have not working? Are you getting an error? What error are you getting?
 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic