Solved

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

Posted on 2004-08-09
6
1,097 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 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
Industry Leaders: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Read  the original post  on Monitis Blog. Hi.  My name is Erik Dietrich, and this is the first time I’ve posted on the Monitis blog.  By way of introduction, I thought it would make sense to talk about my initial experience with Monitis.   Befo…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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