aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question regarding  jsp:include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question regarding  jsp:include" Watch "Question regarding  jsp:include" New topic
Author

Question regarding jsp:include

Deepti Padiyar
Ranch Hand

Joined: Apr 27, 2006
Posts: 31
I understand that <jsp:include> action is used when dynamic content in JSP is needed versus the <%@ include%> directive while using static files.

I have a piece of code with which I am not able to justify the above.

CheckBeanProp.jsp


includeresult.jsp


If I understand right,
the servlet class for CheckBeanProp.jsp will be created and a method call will be inserted in the servlet code (after setting the "Meera" parameter) to call includeresult.jsp at Runtime.
So, the "Meera" parameter should be set to "Hello" in includeresult.jsp.

The actual output thst I get is nothing, that is no parameter that is set in the request.

Why does this code not work? If not this way, how should I best use the <jsp:include> action when I need dynamic output during deployment.

Where am I going wrong?
[ June 21, 2006: Message edited by: Deepti Padiyar ]

Regards,<br />Deepti.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

That input tag does not by itself set any parameters. In fact, parameters can not be set programmatically.

The input tag will only submit parameters when the user submits a form that contains the textfield. Try surrounding the textfield with a form tag and set the action attribute of the form tag to the name of the JSP. Oh yeah, and give it a submit button:

So the first entry of the page still gives no value. But if you click Submit... well, you'll see what happens. Play around with this a bit. Change the textfield's value and resubmit the form. Look at the URL each time you submit (it's in the Address bar of your browser).


A good workman is known by his tools.
Deepti Padiyar
Ranch Hand

Joined: Apr 27, 2006
Posts: 31
parameters can not be set programmatically

That will be a thing to keep in mind... THANKS for the prompt reply.... !
salil verma
Greenhorn

Joined: Jun 03, 2006
Posts: 22
As far as i feel you want to send the parameter to the included file, This can be done using the following steps

Main.jsp
<jsp:include page="Test.jsp">
<jsp aram name="test" value="parameter1 and parameter2"/>
</jsp:include>

Test.jsp

<p> the parameters sent are ${param.test} </p>

using this syntax while accessing the file Main.jsp the contents of Test.jsp will also be displayed with the parameter value even in the first call of Main.jsp
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Ah, thank you, salil! Great job! I totally forgot!

And this would also work:

Main.jsp
<jsp:include page="Test.jsp?test=parameter1 and parameter2" />

Test.jsp
<p> the parameters sent are ${param.test} </p>

Parameters can only be set by adding them to a URL. My first example uses a form to add parameters to the main URL of the request. Once the URL has been sent, you can not change the parameters with code!

But JSP includes have a unique situation however, because they have two URLs from which to retrieve parameters. First, there's the URL for the main page (as in my first example). Second, there's the URL for the included JSP (as in salil's example). If a parameter exists in both URLs, the including JSP will use the parameter closest to it (the one from the include).

What will be the output if I go to the following URL?
http://myApp/Main.jsp?test=abc


The answer is:
abc xyz abc scwcd
[ June 23, 2006: Message edited by: Marc Peabody ]
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Excellent explanation - Thanks for the code examples.



/** Code speaks louder than words */
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question regarding jsp:include