?
Solved

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

Posted on 2004-08-09
6
Medium Priority
?
1,101 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 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