Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Absolute URL in jsp:include

 
Josiel Oliveira
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I put absolute URL in my jsp:include ?
I�m trying to make a include from another web
application, but it always resolves with the
current context.
<jsp:include page="/rightcontext/page.jsp" flush="true" />
/mycontext/rightcontext/page.jsp

Thanks for any advice
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, include and forward will always resolve to the current application context.
All is not lost, since there are ways to communicate between contexts. The problem is that it is highly vendor specific and if you really want to do this you're going to have problems.
It goes like this:
A RequestDispatcher can load (ie include of forward to) a JSP, but a RequestDispatcher is specific to a ServletContext.
From a Servlet, you can get the ServletContext, from a ServletContext you can get a handle to another (named) ServletContext.
From this ServletContext, you can a RequestDispatcher to load the resource.
That's it in theory, as to how it actually works in the server you are using, who knows.
I'd still recommend a sendRedirect to the resource in that context.
(Problems you'll possibly run into: the named context may or may not require a leading slash, since the RequestDispatcher may exist on the other sde of the Thread pool its possible the include could happen just about anywhere in the output. Good luck )
Dave
 
Josiel Oliveira
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David, thanks for answering.
I�m using, in my servlets, the code below to
forward to a different context.
this.getServletContext().getContext("/ApacAdmin").getRequestDispatcher("/any_stuff.jsp").forward(request, response);
It seems to work in Tomcat 3.2.3 and 4.0.1
The problem is still the include tags in pages.
I shall keep trying. Thanks!
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Josiel Oliveira:
David, thanks for answering.
I�m using, in my servlets, the code below to
forward to a different context.
this.getServletContext().getContext("/ApacAdmin").getRequestDispatcher("/any_stuff.jsp").forward(request, response);
It seems to work in Tomcat 3.2.3 and 4.0.1
The problem is still the include tags in pages.
I shall keep trying. Thanks!

JSTL's standard <c:import> tag lets you perform cross-context imports (and, separately, imports via absolute URLs).
For more JSTL (JSP Standard Tag Library) info, see http://java.sun.com/products/jsp/jstl
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic