• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

jsp:include question

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ,

In include1.jsp i have



In include2.jsp :


And i try to invoke include2.jsp.
But it throws me exception :
Unable to compile class for JSP:
y cannot be resolved

So my question is there any way i can access the value of y in my include2.jsp.

Please advise,
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
<@ include file="include1.jsp" />
It should work because

translation vs runtime !!!

Runtime ---> <jsp:include page="include1.jsp" />
Translation ---> <@ include file="include1.jsp" />

Try and let us know
Thanks
AR
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Thanks for the reply
Yes i know it works with include directive.
But was trying with jsp:include action.
Just wanted to know if there is any way i can access that variable in include1.jsp ?
 
Aaron Raja
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to pass paramater!

Here is simple example which pass String just modify and try and let us know.


header.jsp
========

This is my Header page.




<em><strong>${param.subTitle}</strong></em>



mainPage.jsp
=========
<jsp:include page="header.jsp">
<jsp:param name="subTitle"
value="We have taken the string out of SOAP" />
</jsp:include>

Thanks
AR
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aaron,
I still dont get it.
I have to access the variable "y" in my include2.jsp.
And this variable is defined in include1.jsp.
So if do an include for include1.jsp, where and how i pass the parameters.
Can you show me an example with my scenario.

Thanks,
 
Aaron Raja
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
include1.jsp
==============


I am in include1.jsp


Parameter y which is coming from include2.jsp
<em><strong>${param.y}</strong></em>


include2.jsp
============
<jsp:include page="include1.jsp">
<jsp:param name="y" value= 4 />
</jsp:include>

This should work! keep us posted!
Thanks
AR
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aaron,
You misunderstood my question.

Suppose I am in include2.jsp

which looks like :



NOTE: Here y is not defined.

and my include1.jsp has y defined in it as:



So now can i get value of y from include1.jsp, when i invoke include2.jsp ?
Hope my question makes sense now
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit the thing you are talking about is not possible I think. The jsp:include dag use a sort of method call approach to include the output of the included page into the output sent to the client. It is like doing this



So the only solution to this is to use include directive as it copies the code of the included page into the caller page...
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankit is right. Why not you try to read generated servlet codes it will give you better understanding.
 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot.
That clears everything !
 
a wee bit from the empire
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic