|
Hmm..I
am able to forward to a different web-app context no problem..although I am not
sure if it is ok to do so or not. What I do is:
web-app context user is in =
/inside
web-app context user wants to go to =
/
String
forwardPath = "/index.jsp";
String
contextPath = request.getContextPath(); // yields /inside in this
example
ServletContext sc =
getSerlvetContext().getContext(forwardPath);
sc.getRequestDispatcher(forwardPath).forward(request,response);
Right
now this seems to work fine. Maybe its not allowed..but it does work. The caveat
is that I have to use <%= contextPath %> in EVERY resource link, image,
etc on every JSP page. My purpose is to make sure a web-app is properly
developed so that it could be deployed with othe web-apps without any conflict,
any improper resource links, etc.
I am
going to be playing around with this a bit more, but right now it seems to work.
I am only testing this in Orion, so I can't possibly know if it works in other
servlet engines. Needless to say, I did add the redirect capability to my MVC
framework just incase.
Servlet2.3 doesn't specify any sharing between web applications.
You can't forward request from one application to another this is not possible
with existing spec. If you need this kind of functionality you can get
with redirect. As far with servlet2.3 each web application is
independent and their resource loading and class loading are
different.
Kesav Kumar Kolla Voquette Inc 650 356 3740(W)
510 889 6840(R) Voquette...Delivering Sound Information
Hi
all,
Deploying 3 web-apps in one application in Orion; Outside, Inside and
Admin. Outside is mostly static, with a login section. The login section
takes the user to the Inside app by calling
into it via a /inside/Login.do?command=Login (using the popular Struts MVC
syntax). This all works. Using
Struts MVC (and even with my own), it appears that when trying to forward to
a different web-app context, its not possible. At least not yet..could be my
code. In MVC, the ControllerServlet running in one context, tries to forward
to a resource. Almost always this is in the same servlet-context (web-app)
as the ControllerServlet. In my case, I want a user to log out, which takes
them to the outside index.jsp page again. The normal RequestDispatcher() is
part of the Inside web-app context, so when it tries to forward to a
/index.jsp, I would think the / would indicate the context to forward to.
This doesn't appear to work. So then I tried using the
ServletContext.getContext(url) call where the url is the same as the
forwarding resource. Thus, to forward from any web-app to the outside "root"
index.jsp page, I do something like:
getServletContext().getContext("/index.jsp").getRequestDispatcher("/index.jsp").forward(request,
response); This gets the right ServletContext of the root app. I have
tested this by creating an object and setting it as an attribute in the
/index.jsp, and in the ControllerServlet I get the ServletContext and look
up the attribute (before trying to forward), and it finds it. So when using
that ServletContext and trying to forward, its still not finding the page. I
continue to get 404 not found
errors.
My
question is..is it possible to forward from one web-app to another? It
appears to work when I go from the / to the /inside context just fine (at
least it appears that on the JSP page using a href or form action url path
of /inside/Action.do, it does work by calling into the /inside web-app). I
can't imagine that deploying multiple web-apps limits you to not even
forwarding to another web-app. I do know you can't share any data between
web-apps, but being able to jump from one web-app to another via links and
via forwarding should work..shouldn't it? The API isn't exactly clear on
this..but I will look at it again.
Thanks.
|