• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

including an external jsp

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

I have two applications deployed that behave as follows:
App_A jsp executes and then includes App_B jsp's
I want from App_B to call a jsp in App_A

They're sitting on the same server...

Thanks,
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That greatly depends upon what you mean by "call". Do you really mean "include"? Or do you mean "to submit a request to"?

If the former, use <c:import>.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PS. And I'd be unlikely to do things this way. Rather, I'd handle the resource sharing at build-time rather than at run-time.
 
Klament J. Kruoghst
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks bear,

Sorry yes I meant include the jsp on App_A. We don't want to copy all jsp and files into App_B if we dont' have to.
the jsp:include doesn't seem to work, what is that option you mentioned about sharing? I just want to avoid duplications specially this one, it's a lot of code.

I also saw a posting saying c:import could be used but that seems to apply only to different web projects within the same EAR. Both webapps are in different EAR but are running on the same server.

Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<c:import> will work for any URL.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<c:import> will work if you give it an absolute url to work with.
Under the hood it determines if it can do a requestDispatcher include, or if it has to make a seperate http request.

What server are you using?
If it is Tomcat, you can do cross context calls.
You need to
- explicitly configure your application to allow cross context calls in the application.xml for your web app
- call servletContext.getServletContext("/someOtherContext") to get a handle on the foreign context.
- once you have that handle you can get a request dispatcher, and execute forward or include calls that way.
May or may not be possible in your current server.

 
Klament J. Kruoghst
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replies.

I have some questions about it though:

<c:import> will work for any URL.


How do I find the full URL of the jsp I want to import? I tried adding the path but it didn't work ... If I put in the URL the full path I get a so I don't think I can just add that one (actually I did and it didn't work): //server/path/myjsp.jsp

javax.servlet.jsp.JspException: Cannot find bean Headers in any scope


The jsp I want to include is also included in the App_A so i guess i need it to send me whatever is the result text after it has compute, it cannot compute from my App_B.... sorry it this is a bit confusing.

As for:

servletContext.getServletContext("/someOtherContext")



What would the "someOtherContext" be? the apps are running on Weblogic by the way. When I check on weblogic it says for the App_A I want to include:

Context Root: (No Value Assigned)

The Context Root for App_B (where the include is) has some values, so how do I reference an app that has no context root assigned?

Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Klament J. Kruoghst wrote:How do I find the full URL of the jsp I want to import?


You mean at run time? You don't. You need to know the path to the JSP within the other app. You can determine the server part of the URL (as they are running on the same server, as you say), but there's not way to do discovery on the other app.

One more time then I'll be quiet: run-time sharing is fraught with pitfalls -- unless I have a really good reason, I'd vastly prefer build-time sharing of the resources.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Klament J. Kruoghst wrote:so how do I reference an app that has no context root assigned?


All web apps have an assigned context root. The root web app still has a context root, it just happens to be the empty string.
 
Klament J. Kruoghst
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Bear I think the resource is shared, I just don't know how that would help loading this jsp because it's not working.

Ok so here's an example of what I have on my jsp



the <path> is the same path as if it were used inside AppB, the jsp is the same name... basically as if I were using it from AppB... what is it I have to add to that import statement to make it work?
I also added context="/" to the import statement and it didn't work either.

Thanks for the help.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the resource is in another web app, you can't use a server-relative URL, you need to include the whole "http://whatever/" shebang even if they are on the same server. That's what will trigger the tag to suck in the external resource.

Essentially you need to use the same URL that you would use to display the JSP if you typed it into the address bar of the browser.
reply
    Bookmark Topic Watch Topic
  • New Topic