This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes passing parameters to included jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing parameters to included jsp file" Watch "passing parameters to included jsp file" New topic
Author

passing parameters to included jsp file

Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
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


Subbu
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Jun 22, 2001
Posts: 73
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

Joined: Nov 02, 2000
Posts: 195
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

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Jun 22, 2001
Posts: 73
thanks Mike for your help.
i will try out and let you know.

Subbu
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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
 
subject: passing parameters to included jsp file
 
Similar Threads
How can a non-servlet find application root and best way to access a servlets data?
clearing address bar
navigation bar
Presentation logic in the bean, Application logic in the JSP
Updating multiple parts of frame