Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Javaee6 Calling another web resources

Related Tutorials


 
 

Share on Google+Share on Google+

Calling another web resources

Advertisement
In this tutorial you will learn how a web component call to another web resources.

Calling another web resources

In this tutorial you will learn how a web component call to another web resources.

There can another web resources be called by the web components in both direct and indirect way. A web resource that a web component has called is an indirect way of calling by including an URL, this URL indicates the another web component which content will be returned to a client. However a web component calls another web resources directly during its execution, it can be called by either embedding content or by forwarding a request to another resource.

To call a resource it should be available on server, so it is required to get first the RequestDispatcher object. You can get the object of RequestDispatcher by using the getRequestDispatcher("URL") method. This method will return null if either the requested resource is not available or for the requested resource RequestDispatcher object is not implemented by the server.

Embedding the other resources in the response

include(request, response) method of RequestDispatcher object embedded the content with response of another resource while it is returned by the web component. Using this method you can write to the response body but, can't be set headers or call any method.

Passing control to the another web component

Transferring a control to the another web component is sometimes required in the case of where you want to perform some preliminary processing of a request by one web component and the response generation is perform by the another component.

javax.servlet.forward.[request-uri|context-path|servlet-path|path-info|query-string] method of RequestDispatcher is used to transfer the control from one web component to another. The requested URL locates the page that is responsible for replying to the user.

Getting Web Context

getServletContext() method is used to find out the web context, context is an object that implements the ServletContext interface, where the web components are executed. Methods of web context allows to access the following :

  • Initialization parameters
  • Associated resources of web context
  • Object-valued attributes
  • Logging capabilities

getAttribute() method is used by the filter to find out the counter object's.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 2, 2011

Related Tutorials

Discuss: Calling another web resources  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Meena
March 3, 2012
Calling another web resource

I NEED to move my JSP from one application to another domain where it can access the db & other resources as before. We need to put a simple JSP file into another application. And this application is located in another domain which is different from the domain that our application exists on. We don’t want to bring risks to that application, so we need a solution to control the access only permit the requests from our application to this JSP file. Since this JSP exists on another domain, so it could not visit any other resource such as DB in our application to get the security information.
DMCA.com