Solved

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

Posted on 2004-08-09
6
1,088 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JspWriter.write() and JspWriter.print() 4 81
xjc and jaxb 2 90
servlet cookie finding by name 1 70
How to find missing packages when using Netbeans IDE 8.1 ? 19 46
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
OpenVPN is a great open source VPN server that is capable of providing quick and easy VPN access to your network on the cheap.  By default the software is configured to allow open access to your network.  But what if you want to restrict users to on…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 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

22 Experts available now in Live!

Get 1:1 Help Now