Solved

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

Posted on 2004-08-09
6
1,095 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 651
How can I   ajax html table  rows? 20 78
ejb on wildfly 5 30
mysql jsp example issue 32 48
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?

791 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