• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:include question

 
Amit Hetawal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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,
 
Aaron Raja
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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...
 
gurneeraj singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot.
That clears everything !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic