wood burning stoves 2.0*
The moose likes Servlets and the fly likes call servlet files from different war Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "call servlet files from different war" Watch "call servlet files from different war" New topic
Author

call servlet files from different war

Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
hi all,
I have 3 different .war (web application) and deployed in weblogic server.
Each .war contains one servlet file. I need to pass information from
one servlet to another servlet and also need to send extra parameters from the first
servlet(reside in first .war) to second servlet(reside in second .war).
RequestDispatcher is good solution?
Pls explain me..
tks
jowsaki
Alain Boucher
Ranch Hand

Joined: Feb 25, 2003
Posts: 51
Before forwarding your request do a request.setAttribute(key, your data). Also you can put information in the ServletContext.


Alain Boucher<br />Spare-Brain Consultants Inc.<br />SCJ2P,SCWCD,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

You cannot forward to a resource that is outside of the current servlet context.
Can you not just post a request to the servlet in the other context using request parameters to communicate?
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
HI Alain,
I hv 2 war files and each contains one servlets. From which am passing info from one servlet
to another servlet by using RequestDispatcher.
For eg. one.war - one.java (Servlet)
two.war - two.java (servlet)
I hv deployed the 2 war files in Weblogic servlet and forward the request from
one.servlet to two servlet. am gettin file not found eror
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

Am using the following method to forward..
RequestDispatcher rd=getServletContext().getRequestDispatcher("/two/two");
Pls guide me.. how to solve.
tks
jowsaki
jack jr
Greenhorn

Joined: Jan 12, 2003
Posts: 4
Hi,
Have you tried to get a dispatcher using two's virtual name(i.e. url) ?
On the other hand, an EJB could solve the problem for sure, i think.
Hope it helps,
Jack
SCJP but not SCWCD yet.
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
u meant like
http://localhost:7001/dir/ServletName
Tks
jowsaki
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Read Bear's post again.. a web application's request dispatcher only knows about resources within that application.
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Hi all,
Is there solution to send info from one servlet to another servlet (both are in different web applications .war).
Help me out..
tks
jowsaki
jack jr
Greenhorn

Joined: Jan 12, 2003
Posts: 4
Hi,
I got the solution now Just look the api!!
public RequestDispatcher getRequestDispatcher(java.lang.String path)
...
The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.
Then you go to see getContext:
This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container.
In a security conscious environment, the servlet container may return null for a given URL.
These are all in the api ...
jack
jack jr
Greenhorn

Joined: Jan 12, 2003
Posts: 4
so bear's comment should be: you cannot forward to something outside your server's context root, while your server can have many applications(wars) and every of them has their own context root.
I guess if you want to foward to another server, then it looks like web service or rmi etc.
Jack
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Hi jack,
Can you pls explain with example.. i was trying the same error is coming.. pls explain me..
thks
jowsaki
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Hi ALL,
Am getting the following error while calling one servlet to another servlet (different .war files)
---------------------
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.

----------------
pls help me out with examples..
tks
jowsaki
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
HI All,
Yes I got it.. after using getContext().
this is my solution for others
For example, Servlet A in Web application A can obtain the ServletContext for Web application B, as long as both Web applications are defined under the same virtual host. After Servlet A obtains the servlet context for B, it can access the request dispatcher for servlets in Web application B and can call the getAttribute() and setAttribute() methods of the servlet context. The following sample shows an example of the coding in Servlet A:
appBcontext = appAcontext.getContext("/appB");
appBcontext.getRequestDispatcher("/servletB");
Thanks
Cheers
Jowsaki
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: call servlet files from different war
 
Similar Threads
What do I need to run servlets?
Need to refer a Javascript from another WAR file
Need to access Java methods and javascript functions in a WAR file from another WAR
EJB in WAR Accessible from Components in Other Modules?
Is it possible to have connection to two different pools in the same method?