how can i run an action class as soon as i asked for a jsp page.

Discussions

Web tier: servlets, JSP, Web frameworks: how can i run an action class as soon as i asked for a jsp page.

  1. Hi,
     
       I have a jsp page, with some struts library tags.
    I am using a <html:text ..></html:text> and i want to populate some value throgh a session attribute from one action class. my jsp page is welcome page.
      
       How can I execute the action class initially..
    I have no submit buttons.

    Regards,
    MaRu.
  2. If I understand you correctly you want to get data from an Action class if you go to /welcome.jsp, correct?

    Sorry, I don't know the Struts tags well enough but this is easily done in Webwork with the action tag, <ww:action name="<action class>" /> and it will call the execute method in the action class name.

    If struts does not have this feature I can't imagine it being to hard to do with a custom tag.... I imagine someone has done this before.

    Kris Thompson
  3. Hi,    I have a jsp page, with some struts library tags.I am using a <html:text ..></html:text> and i want to populate some value throgh a session attribute from one action class. my jsp page is welcome page.     How can I execute the action class initially..I have no submit buttons.Regards,MaRu.
    Create a Form Class which extends ActionForm with get and set methods for your JSP, Declare the form bean with your action in strust-config.xml. Populate the values in your action class to your form class and forward it to your jsp. The request should go through your action class.

    Hope this helps,
    Senthil.
  4. Create an Action(welcome.do) and associate it with an Action class(welcome.class). Also associate a Forward to Welcome.jsp to the same Action Mapping. At end of execute method in Action class foward to welcome.jsp forward. Set the default page for the website to welcome.do.
    A call to welcome.do will initially call the Action class
  5. This works only if the request scope is set to "request" rather than "session"