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...
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.
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.
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.
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?
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.
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.
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.
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.