How to merely retrieve data? - Newbie looking for best practices
Greetings! First, I'm new to Struts, and pretty green in my Java skills, but I'm excited about learning both! My goal is to retrieve data, which a jsp will spill out. I'm trying to do it by writing a simple Action subclass to get the data and send it along. The way I'm doing it isn't working. My action mapping looks like this: action path=/records type=app.actions.RecordsAction forward=/pages/records.jsp / My app.actions.RecordsAction looks approximately like this: public class RecordsAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{ RecordList rl = new RecordList(); //Object used to get records List l = rl.getRecords(); request.setAttribute(records,l); return mapping.findForward(could-be-anything); } } The result is that I get forwarded to /pages/records.jsp without the execute method ever being called in RecordsAction, and as such, I get a null pointer when I try to do anything with the request.getAttribute(records) in the jsp. However, this seems to make perfect sense because I specified this to merely forward. So, how do I get the data? If I want to simply return dynamically generated content, without an ActionForm, what's the best practice for retrieving it? 1.What should the Action subclass look like? 2. What would the action-mapping in struts-config.xml look like? 3. Is it common to use request.setAttribute(value) to send data to the View? and if not, what's the correct way to send data to the View layer? (I think this is the pivotal question) I've been going through Struts in Action, which I find good as a technical reference, but not so good when it comes to figuring out how to achieve a simple goal, like this. In my quick research in the book and online, everything I've found seems to be tied to ActionForms. But I don't have an ActionForm. Alas! I realize that I am probably missing something fundamentally basic and that y'all might tell me to go RTFM. And that's cool, just point me to it. Most of the stuff I've seen is very focussed on dealing with data AND forms, but not data by itself. I'd be happy to find some recommended documentation. Thanks for your collective help in getting me on track! Eric Rank - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to merely retrieve data? - Newbie looking for best practices
On 1/7/06, Eric Rank [EMAIL PROTECTED] wrote: My goal is to retrieve data, which a jsp will spill out. I'm trying to do it by writing a simple Action subclass to get the data and send it along. The way I'm doing it isn't working. My action mapping looks like this: action path=/records type=app.actions.RecordsAction forward=/pages/records.jsp / Welcome! There's quite a bit of information in the DTD itself: http://struts.apache.org/dtds/struts-config/1_2/ Click on 'action' and then scroll up a bit to read the comments. For forward, it says: Exactly one of forward, include, or type must be specified. Instead of the forward attribute, try using a nested (or global) forward name=could-be-anything path=/pages/records.jsp / element. And yes, setting attributes in the request or session and retrieving them in the JSP is a reasonable thing to do. Take a look at JSTL if you aren't already using it. -- Wendy - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to merely retrieve data? - Newbie looking for best practices
Ahhh yes. Actually, I did check out the DTD a couple of days ago. I remember it saying how you can only put in one forward include or type. I just didn't connect how I would set a type and then specify a forward as the child node. Now it works just fine. I knew it was probably something simple. I appreciate your help! Thanks, Eric On 1/7/06, Wendy Smoak [EMAIL PROTECTED] wrote: On 1/7/06, Eric Rank [EMAIL PROTECTED] wrote: My goal is to retrieve data, which a jsp will spill out. I'm trying to do it by writing a simple Action subclass to get the data and send it along. The way I'm doing it isn't working. My action mapping looks like this: action path=/records type=app.actions.RecordsAction forward=/pages/records.jsp / Welcome! There's quite a bit of information in the DTD itself: http://struts.apache.org/dtds/struts-config/1_2/ Click on 'action' and then scroll up a bit to read the comments. For forward, it says: Exactly one of forward, include, or type must be specified. Instead of the forward attribute, try using a nested (or global) forward name=could-be-anything path=/pages/records.jsp / element. And yes, setting attributes in the request or session and retrieving them in the JSP is a reasonable thing to do. Take a look at JSTL if you aren't already using it. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]