• 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

call servlet files from different war

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before forwarding your request do a request.setAttribute(key, your data). Also you can put information in the ServletContext.
 
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
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
 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
u meant like
http://localhost:7001/dir/ServletName
Tks
jowsaki
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read Bear's post again.. a web application's request dispatcher only knows about resources within that application.
 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic