Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp:include  RSS feed

 
Roger Beganza
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help on the following?
Suppose I have 2 jsps named as One.jsp and Two.jsp. Now One.jsp includes Two.jsp using <jsp:include> tag. What I want is I could fetch the name One.jsp in the code of Two.jsp somehow. I am not sure whether it is possible or not? I have kind of feeling that we can retrieve the name of One.jsp in the code of Two.jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what purpose? This raises all sorts of red flags about poor design by creating a strong binding between the files.

Please explain what you are trying to accomplish, not how you are going about doing it.
 
Roger Beganza
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed! This is what I feel too but due to some reasons changes in the design are not possible right now , so could you please tell me if its possible or not and if yes then how ??
 
Roger Beganza
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and ya , thanks for your quick response
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still haven't answered my question though.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't think of any way in the API for a jsp page to find out what resource it is being included in.
Its not something you normally need to know.

You CAN get hold of the original URI that triggered the request
It will be stored in a request attribute: java.servlet.include.request_uri (Servlet Spec SRV.8.3.1)
So you can get at it by
request.getAttribute("java.servlet.include.request_uri")
or
${requestScope['java.servlet.include.request_uri']}

Another alternative is just to set a request attribute yourself in one.jsp, and get it in two.jsp.
That would be the simplest, most effective way of passing information between the two.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think of it like Java. If you want a method to do something conditional within it, do you have the method find out where it was called from?

Of course not. You pass it the information it needs to make its decisions.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also wish to consider using a tag file rather than an include. That allows for a clearcut means to pass information into the reusable code.
 
Roger Beganza
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stephen,

request.getRequestURI() worked for me. :-)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's the hair-pulling smilie when you need it?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!