Solved

How to include a struts action in a page - without using tiles

Posted on 2004-08-09
6
1,087 Views
Last Modified: 2008-02-26
I have a menu that is included on all pages in my web app. I initially created a jsp called "leftmenu.jsp" and included in on all pages using <jsp:include>.

I now need to dynamically generate menu depending on menu lements defined in the database. I thought I'd make a "LeftMenuAction" which I'd include in the pages instead of the leftmenu.jsp. The LeftMenuAction would read the collection of buttons from the database, store them in the request, then forward the request to the leftmenu.jsp.

However. I can't seem to get this to work with either the <jsp:include> or <bean:include>. The current error I'm getting is a java.io.IOException: Stream closed.

Reading through some reference material, it doesn't explicitly say you can do what I'm trying to do with either include method... I'm wondering is tiles the only way? I was hoping to avoid tiles for our first struts project.

Thanks in advance,

Jason
0
Comment
Question by:jjoz
6 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 11760182
I think you have to use tiles...  Either that, or a jsp with dataaccess beans like you had (with jsp:include)

If you use tiles, it's much neater, as you only need to put the left menu jsp into the main layout for the site, and so it is only included in one place (instead of in every page)
0
 
LVL 9

Accepted Solution

by:
nimaig earned 500 total points
ID: 11760665
Tiles is the best option but you can try something like this.


Make a base action which can be a abstract class. Like

public abstract class BaseAction extends Action
{

      public ActionForward execute( ActionMapping mapping,
                                      ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response)
               throws Exception
    {
          ...
          //Get the menu and set it in the context/request
          ...
          //Call your own method which must be implemented by any action class extending the BaseAction
          ActionForward af = executeAction( mapping,form,request,response);
                              
              return af
    }
   
    abstract public ActionForward executeAction( ActionMapping mapping,
                                                           ActionForm form,
                                                           HttpServletRequest request,
                                                           HttpServletResponse response,
                                                        )
    throws Exception;

}


In 'leftmenu.jsp', get the metu items and display.

0
 
LVL 4

Expert Comment

by:Mr_It
ID: 11760836
Maybe the JSTL tag <c:import> can do the trick. I also had IO problems with <jsp:include>.
<c:import> did the magic...
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

by:Mr_It
ID: 11761907
It's probably because you write to the outputstream while it's allready being sent back to the client. You can only write to it, when nothing is being sent back to the client...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11761937
> You can only write to it, when nothing is being sent back to the client...

And it has not been flushed and closed (as in this case I think)
0
 
LVL 1

Author Comment

by:jjoz
ID: 11768731
Thanks for all the speedy responses, most appreciated.

I decided I still want to avoid tiles on this project, but got some inspiration from some of your answers. I went back to including a jsp, but now load the tasks up in a RequestProcessor servlet that I already used to implement the application security.

Wish I could give you all some points, but I'll have to settle on nimaig's answer as it gave me the inspiration :)






0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now