This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing parameters to included jsp file

 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have one question.i have written a reusable navigation bar as a jsp page.i am planning to include this file in other jsp pages.my problem is i want to enable some buttons while disabling others depending upon the situation.
is there a way by which i can pass parameters to the navigation bar jsp page so as to disable some bottons.if not, is there any other way i can achieve this.
Thanks.
Subbu
 
Brian Nice
Ranch Hand
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this would work- include your page using <jsp:include page="file"> and add a parameter telling which menu should be selected <jsp aram name="menu" value="menu1"/> and close the </jsp:include>
now when your file is included, reference the value menu.
Brian
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They share the same request and response (and session) objects, so you can use setAttribute to place extra data on the request before passing on to the included page.
Dave.
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Nice:
I think this would work- include your page using <jsp:include page="file"> and add a parameter telling which menu should be selected <jsp aram name="menu" value="menu1"/> and close the </jsp:include>
now when your file is included, reference the value menu.
Brian

Hi Brian,
According to Marty Hall(author of core servlets and java server pages), <jsp:include> can be used to include static html file and not jsp file.i am not sure how we can do the thing you have suggested.can u give an example of how to do it.

Originally posted by David O'Meara:
They share the same request and response (and session) objects, so you can use setAttribute to place extra data on the request before passing on to the included page.
Dave.

Hi Dave,
Here we are not passing the request and response objects to the included file.or in other words, we are not passing the control to the navigation bar jsp.we are just including the output of included jsp file in the output of the current jsp file.
What do you suggest now?
Subbu
 
Brian Nice
Ranch Hand
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a very simple example that works on my machine by using <jsp:include>
-------test.jsp
<jsp:include page="inclusion.jsp">
<jsp aram name="menu" value="obj2"/>
</jsp:include>
-------inclusion.jsp
<
<% String menu = request.getParameter("menu");
if (menu.equals("obj1")) { %>
This is object one
<% } else { %>
This is NOT object one
<% } %>
------
By changing the value of the menu parameter in test.jsp you can change what the included inclusion.jsp file prints out. Does that help?
Brian
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just thought I'd comment on this:

He is not the only author to get this wrong. The first edition of Pro JSP confused me in this respect, and the 2nd edition has fixed this mistake by rewriting the entire chapter.

It's the other include (page directive) that will include static text. I use the following to include style definitions:
The following example uses the action tag and is used for dynamic content...
You will see that by alternately requesting UsingPage.jsp and UsingPage2.jsp, the contents below the < hr > change, and the number increases. Proof that the action tag is the dynamic one.
[This message has been edited by Mike Curwen (edited July 23, 2001).]
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Mike for your help.
i will try out and let you know.

Subbu
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should include a clarification on this topic, it is quite confusing for the un-initiated.

Some grammar:
'Directive include' means < %@ include page="pageName" >
'Action include' means < jsp:include page="pageName" flush="true" >

When the directive include is used, this is a 'static' inclusion, that can be either static * or * dynamic content. That is: the included file can also be a JSP. But I consider the directive include to be 'static' in nature, because it is done once only... at JSP compile time.

When the action include is used, this is a dynamic inclusion in all senses of that word. The included file can again be static or dynamic... but including a static file with this tag would be a waste of processor cycles... because every single request for the JSP will result in the included file being 're-included'... so if the included file is dynamic (ie: it's a JSP), the content is not only dynamic, but the inclusion *of that file* is also dynamic.

Hope that assists people. I was reading iPlanet App Server docs and they get things just *wrong*. Or else they are not clear on specifying what they mean be 'static' and 'dynamic' (are they talking about when it's included, or the resource included?).

Summary:
Directive - inclusion static, content static or dynamic
Action - inclusion dynamic, content static or dynamic

p.s. - iPlanet sucks, because iAS SP2 doesn't suport the <jsp:param /> tags inside of <jsp:include /> !!! What is the point of using jsp:include then?? Argh.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic