Calling another servlet in other server

Hi - a quick newbie question -
I need to call a servlet sitting on another server via http.
I'm thinking of doing following..
URL url = new URL("http",HOSTNAME_,PORT_, "/sp/xmlBuilderRates?" + urlParams );
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
// now how would I pass back output stream? to the original response object?
uc.getOutputStream();
Thanks

I was looking to find a way to somehow relay child's servlet's output to current response object's output - streaming
Maybe something like
URL url = new URL("http","nyfddapp02",8889,"/sp/xmlReport?" + urlParams );
BufferedReader in = new BufferedReader( new InputStreamReader( url.openStream()));
String line;
while( ( line = in.readLine()) != null )
out.println( line );
out.flush();

Similar Messages

  • Calling another servlet from a servlet

    I'm working on a servlet and would like to know how to
    call another servlet, by clicking on a form button
    or a hyperlink that was generated from the first servlet,
    is it only possible if the second servlet is called
    in an shtml page? Can you please give me an example
    of how to do this not using shtml pages?
    (I'm working with JDeveloper 2.0)
    When will the book be out for JDeveloper 2.0?
    We're also having problems deploying the servlet
    to the Java Web Server (1.1.3)
    It seems to have a problem connecting to the database.
    We get the first page of the servlet but the
    second page is generated from the doPost()
    and connects to the database using oracle JDBC thin
    gives a http 500 internal server error ,
    and we followed the instructions from JDeveloper
    can the problem be caused from the connection string that
    I used in the servlet:
    Class.forName("oracle.jdbc.driver.OracleDriver");
    DriverManager.registerDriver(
    new oracle.jdbc.driver.OracleDriver());
    con = DriverManager.getConnection(
    "jdbc:oracle:thin:@(description=(address=
    (host=10.10.10.53)(protocol=tcp)(port=1521))
    (connect_data=(sid=OR8A)))",
    "im_dev","im_dev");
    or the configuration of the web server?
    (web server: Solaris 2.7 running on Intel)
    null

    Hi
    The sample acme video demo in JDeveloper does something similar.
    It has main Servlet "WebAppServlet.java" which overides the
    doPost and doGet methods and this methods calls someother java
    classes do perform some specific business logic which return a
    html page in a String format to "WebAppServlet.java".
    Open the samples directory in JDEveloper 2.0 with WebApp_81.jws
    to look at the source code.
    Steps to run the sample are included in the help system.
    regards
    argyro (guest) wrote:
    : I'm working on a servlet and would like to know how to
    : call another servlet, by clicking on a form button
    : or a hyperlink that was generated from the first servlet,
    : is it only possible if the second servlet is called
    : in an shtml page? Can you please give me an example
    : of how to do this not using shtml pages?
    : (I'm working with JDeveloper 2.0)
    : When will the book be out for JDeveloper 2.0?
    : We're also having problems deploying the servlet
    : to the Java Web Server (1.1.3)
    : It seems to have a problem connecting to the database.
    : We get the first page of the servlet but the
    : second page is generated from the doPost()
    : and connects to the database using oracle JDBC thin
    : gives a http 500 internal server error ,
    : and we followed the instructions from JDeveloper
    : can the problem be caused from the connection string that
    : I used in the servlet:
    : Class.forName("oracle.jdbc.driver.OracleDriver");
    : DriverManager.registerDriver(
    : new oracle.jdbc.driver.OracleDriver());
    : con = DriverManager.getConnection(
    : "jdbc:oracle:thin:@(description=(address=
    : (host=10.10.10.53)(protocol=tcp)(port=1521))
    : (connect_data=(sid=OR8A)))",
    : "im_dev","im_dev");
    : or the configuration of the web server?
    : (web server: Solaris 2.7 running on Intel)
    null

  • Servlet calling another servlet

    hi,
    I am writing a web-application which requires one servlet (on main server) to call another servlet (on a remote server).
    The main servlet needs to call the remote one and send some parameters to it.
    The remote servlet would be sending back XML data which is to be used by the central servlet. I tried using XML-RPC but it does'nt seem to support sending in NATIVE XML data.
    I also tried by creating URL, but did not find a way to add parameters to it !!!
    Could anyone please tell me how to call another servlet (along with sending POST/GET parameters) and get the results back into the calling servlet ?
    Any suggestions would be greatly appreciated.
    Thanks !
    Ajoy

    one possible solution would be to create an own socket connection (this would be a like a Post request) and than exchange data as you like.

  • I want to send a response from the servlet and then call another servlet.

    Hi,
    I want to send a response from the servlet and then call another servlet. can this happen. Here is my scenario.
    1. Capture all the information from a form including an Email address and submit it to a servlet.
    2. Now send a message to the browser that the request will be processed and mailed.
    3. Now execute the request and give a mail to the mentioned Email.
    Can this be done in any way even by calling another servlet from within a servlet or any other way.
    Can any one Please help me out.
    Thanks,
    Ramesh

    Maybe that will help you (This is registration sample):
    1.You have Registration.html;
    2.You have Registration servlet;
    3.You have CheckUser servlet;
    4.And last you have Dispatcher between all.
    See the code:
    Registration.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
      <HEAD>
        <TITLE>Hello registration</TITLE>
      </HEAD>
      <BODY>
      <H1>Entry</H1>
    <FORM ACTION="helloservlet" METHOD="POST">
    <LEFT>
    User: <INPUT TYPE="TEXT" NAME="login" SIZE=10><BR>
    Password: <INPUT TYPE="PASSWORD" NAME="password" SIZE=10><BR>
    <P>
    <TABLE CELLSPACING=1>
    <TR>
    <TH><SMALL>
    <INPUT TYPE="SUBMIT" NAME="logon" VALUE="Entry">
    </SMALL>
    <TH><SMALL>
    <INPUT TYPE="SUBMIT" NAME="registration" VALUE="Registration">
    </SMALL>
    </TABLE>
    </LEFT>
    </FORM>
    <BR>
      </BODY>
    </HTML>
    Dispatcher.java
    package mybeans;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.ServletException;
    import java.io.IOException;
    import javax.servlet.RequestDispatcher;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Dispatcher extends HttpServlet {
        protected void forward(String address, HttpServletRequest request,
                               HttpServletResponse response)
                               throws ServletException, IOException {
                                   RequestDispatcher dispatcher = getServletContext().
                                   getRequestDispatcher(address);
                                   dispatcher.forward(request, response);
    Registration.java
    package mybeans;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Registration extends Dispatcher {
        public String getServletInfo() {
            return "Registration servlet";
        public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            ServletContext ctx = getServletContext();
            if(request.getParameter("logon") != null) {          
                this.forward("/CheckUser", request, response);
            else if (request.getParameter("registration") != null)  {         
                this.forward("/registration.html", request, response);
    CheckUser.java
    package mybeans;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class CheckUser extends Dispatcher {
        Connection conn;
        Statement stat;
        ResultSet rs;
          String cur_UserName;
        public static String cur_UserSurname;;
        String cur_UserOtchestvo;
        public String getServletInfo() {
            return "Registration servlet";
        public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            try{
                ServletContext ctx = getServletContext();
                Class.forName("oracle.jdbc.driver.OracleDriver");
                conn = DriverManager.getConnection("jdbc:oracle:oci:@eugenz","SYSTEM", "manager");
                stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
               String queryDB = "SELECT ID, Login, Password FROM TLogon WHERE Login = ? AND Password = ?";
                PreparedStatement ps = conn.prepareStatement(queryDB); 
               User user = new User();
            user.setLogin(request.getParameter("login"));
            String cur_Login = user.getLogin();
            ps.setString(1, cur_Login);
            user.setPassword(request.getParameter("password"));
            String cur_Password = user.getPassword();
            ps.setString(2, cur_Password);
         Password = admin");
            rs = ps.executeQuery();
                 String sn = "Zatoka";
            String n = "Eugen";
            String queryPeople = "SELECT ID, Surname FROM People WHERE ID = ?";
           PreparedStatement psPeople = conn.prepareStatement(queryPeople);
                      if(rs.next()) {
                int logonID = rs.getInt("ID");
                psPeople.setInt(1, logonID);
                rs = psPeople.executeQuery();
                rs.next();
                       user.setSurname(rs.getString("Surname"));
              FROM TLogon, People WHERE TLogon.ID = People.ID";
                       ctx.setAttribute("user", user);
                this.forward("/successLogin.jsp", request, response);
            this.forward("/registration.html", request, response);
            catch(Exception exception) {
    }CheckUser.java maybe incorrect, but it's not serious, because see the principe (conception).
    Main is Dispatcher.java. This class is dispatcher between all servlets.

  • Servlets calls another servlet

    servlets calls another servlet ...how to do it ? whats the efficient way ?
    class myservlet extends HttpServlet
    // i want to call a servlet situated at another machine in the LAN whose, IP // 123.123.45.66 (say)
    the servlet which is situated in another machine
    remoteservlet extends HttpServlet
    doPost(...)
    how do i call ?
    few of the way i found by searching the forum.
    but i would like to know the good way in my situation.

    res.sendRedirect("LoginServlet?="+req.getRequestURI())
    i tested this. it does not work.
    my servlet wants to call another servlet which is
    active on IP xxx.ddd.ffff.zzz in the LAN .
    whats the way ?
    res.sendRedirect("http://xxx.ddd.ffff.zzz:<portnumber>/<context_name>/<servlet_regd_name">);The request and response objects are generated anew for that Servlet. There's no two ways about it, IMO.
    cheers,
    ram.

  • How to calling another servlet in a servlet

    In my servlet named TransferServlet I want call another servlet named PublisherServlet. So I wrote codes :
    objURL = new URL("http://localhost:8080/servlet/PublisherServlet") ;
    hucConnection = (HttpURLConnection)objURL.openConnection() ;
    hucConnection.setDoOutput(true) ;
    hucConnection.setUseCaches(false) ;
    hucConnection.setRequestMethod("POST") ;
    hucConnection.connect() ;
    but i can't invoke PublisherServlet. Why ? pls help
    Thanks a lot

    you do not need hucConnection.connect(); hucConnection = (HttpURLConnection)objURL.openConnection() does this.
    You need to use hucConnection.getOutputStream() and write to the stream to post and if you wanted a response you would need to read from hucConnection.getInputStream()

  • Servlet Calls another Servlet, Returns an Object

    Is it possible to call another servlet (which is loaded through
              Load-on-startup) from another servlet. The return should be an Object.
              I know I am kind of asking for a procedural way of programming.
              Example : Servlet "IamReady" is loaded and gets a request with binary
              data. It replies with a Binary Object.
              Servlet "serviceCall" calls IamReady to get the resoponse.
              I know that there are forward (using requestDispatcher) and "include"
              directives to have another servlet service calling servlet.
              Also, if I define a method in the (generic servlet) does each call to
              methos is executed in different thread (like doPost and doGet).
              Thanks.
              Chris
              

    "Michael Reiche" <[email protected]> wrote in message news:<[email protected]>...
              Thank you Michael,
              > It is possible to call a servlet from a servlet.
              >
              > You can 'return' an object by putting it in the httpRequest.
              You mean httpResponse.
              >
              > The call is NOT executed in a separate thread.
              >
              > From this post (and the other post about a connection pool) - I wonder if
              > you really need to be using servlets. I couldn't think of a good reason why
              > the connection pool needs to be a servlet.
              Are you suggesting I should just have a class. Reason I have it as
              servlet, b'caz I do a load-on-startup and do initialiazation etc. in
              the init method. May be if you suggest how I can do it otherwise, I
              would like to implement it that way.
              Thanks again.
              >
              > Mike
              >
              > "MOL" <[email protected]> wrote in message
              > news:[email protected]...
              > > Is it possible to call another servlet (which is loaded through
              > > Load-on-startup) from another servlet. The return should be an Object.
              > > I know I am kind of asking for a procedural way of programming.
              > >
              > > Example : Servlet "IamReady" is loaded and gets a request with binary
              > > data. It replies with a Binary Object.
              > >
              > > Servlet "serviceCall" calls IamReady to get the resoponse.
              > >
              > > I know that there are forward (using requestDispatcher) and "include"
              > > directives to have another servlet service calling servlet.
              > >
              > > Also, if I define a method in the (generic servlet) does each call to
              > > methos is executed in different thread (like doPost and doGet).
              > >
              > > Thanks.
              > >
              > > Chris
              

  • How to call a other servlet in other server

    I want to forward a request coming from one HTTP Client to another servlet which is in other web server. Is it possible? If Possible how can I do it?
    Can anybody explain with an example.
    Thanks,
    Thiru

    You could open an HttpURLConnection to the other servlet and recieve the output from the servlet and incorporate this output into the first servlet's response. You will not be able to directly pass the original request to the second servlet but can construct a new request to the second servlet.

  • Servlet calling another servlet in diff J2EE app

    Hi.
    Can a servlet load another servlet in different J2EE application ?
    If so, could you show me how ?
    Code example would be much appreicated.
    Thanks.

    Call the other servlet's absolute url thro' urlconnection.
    URL url=new URL("http://server:port/servlet/otherservlet");
    InputStream in=url.openConnection();
    Other servlet will be loaded. Read response if you want to.

  • A servlet calling another servlet on diff machine

    plzzzz help me on how i will call a servlet which is running
    on different machine from one machine. and how i will call a servlet
    which is running in different context on the same machine

    To call a servlet on a different machine you can use the HttpURLConnection class. Search the forum for details on how to do this.
    Or you can use the JSTL c:include tag. (or is it c:import?)
    To call a servlet on the same machine in a different context you use
    getServletContext().getServletContext(url)
    where url is the url to the servlet in the other context. Then you can use the RequestDispatcher to forward the request to the other servlet.

  • Calling another servlet.

    Hello,
    Following is an excerpt from our beloved Kathy
    <code>
    RequestDispatcher view=request.getRequestDispatcher("result.jsp");
    </code>
    and
    <code>
    RequestDispatcher view=getServletContext().getRequestDispatcher("/result.jsp");
    </code>
    She has mentioned how to forward a request to another JSP.
    JSPs are in the root of webapp but servlets lie deep inside . My question is how to forward this request to another servlet??

    Sugdya wrote:
    Hello,
    Following is an excerpt from our beloved KathyWho's Kathy?
    She has mentioned how to forward a request to another JSP.
    JSPs are in the root of webapp but servlets lie deep inside . My question is how to forward this request to another servlet??That's the physical filesystem layout. The web container makes a logical layout depending on your mappings. And by the way, JSPs get translated into servlets too.
    Perhaps Kathy explains it later in whatever it is that you're referring to?
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • MVC call another controller with other (own) namespace

    Hello,
    i have a bsp-application (mvc) in our own namespace '/otto/...'. Now i'd like to create a controller, but this controller is in the z-namespace.
    I have tried with the method create_controller and the optional attributes application_namespace and application_name, but it didn't worked!?
    I have tried also with upper case, lower case, full path,
    relative path, but it didn't worked! What is wrong?
    Thank you. Lars

    OK, sorry, i know this options and i use it, but the  answer is the same:
    "500 SAP Internal Server Error
    Fehlermeldung: Es ist eine Ausnahme aufgetreten, die nicht abgefangen wurde. ( Abbruchsart: RABAX_STATE )"
    i was looking in the 'ST22' there are the following information:
    The Error was in the ABAP-Program "CL_BSP_PAGE_BASE==============CP " in           
    "CREATE_PAGE". Mainprogram was "SAPMHTTP ".                               
    In the sourcecode line 1170 from (Include-)Programs "CL_BSP_PAGE_BASE==============CM01B ".
    call method cl_o2_rt_support=>get_class_for_page 
       exporting                                      
         p_namespace      = l_app_nspace              
         p_application    = l_app_name                
         p_page           = l_page_name               
       importing                                      
         p_pageclass      = l_page_class              
         p_pageparams     = l_page_parameters         
         p_html_pool      = l_page_html_pool          
         p_script         = l_page_script_code        
         p_options        = l_page_options            
         p_pagetype       = l_page_type               
       exceptions                                     
         error_occured       = 1                      
         object_not_existing = 2.                     
    case sy-subrc.                                   
       when 1.                                        
         raise exception type cx_bsp_einternal.       
       when 2.    
    1170!                                   
    >  raise exception type cx_bsp_inv_page         
           exporting page = l_page_name url = l_url.  
    endcase.

  • Calling a servlets multiple times from a servlet

    Hi All,
    Advanced Thanks,
    I have a servlet which calls another servlet to display some records. Second servlet will access some data from XML files and forwards to a JSP file. What i want is I need to call the second servlet multiple times from the the first servlet. I used RequestDispatcher to call the servlet but I can call only one time after a an exceptions is occurred like cannot forward after response is committed.
    I need this scenario in the saem way because each time second servlet is called I am forwarding response to user each time records are accessed based on the request value.
    request.getRequestDispatcher("sample").forward(request, response);          
    Any one please give me a suggestion?
    Thanks in advance

    What are those servlets supposed to do? Sounds like that they are doing too much, e.g. acting like business classes or utility classes or so. Refactor your code.

  • How can Servlet includel another servlet?

    I want to have a servlet calling another servlet in the middle of code... how to do that ?
    eg
    Servlet 1 print
    line1..
    line2...
    <-- here include Servlet2 to print line 3 and line 4 -->
    then servlet 1 continue to print
    line 5
    line6

    request.getRequestDispatcher("/servlet/MyServlet").include(request, response);

  • How to call a servlet from another servlet

    hi everybody,
    i have a problem, i have to call one servlet from another one.
    Everything works on my pc, but when i install the application on the customer's server i got an error about an Uknown URL followed by the name of the machine.
    Wjat i do is the folloqing :
    String urlString = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+servletName;
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    the variable servletName is the name of the servlet i have to call.
    Is there another way to call the servlet ?
    All the servlet are installed in the same server.
    Any suggestion ?
    Cheers.
    Stefano

    Sweep is correct about requestDispatcher being another approach for inter-servlet delegation; the only issue that i recall with this approach is that it defaults the method of the destination servlet to the one it was called from...for example, calling servlet2 from within servlet1.post() resulted in the dispatcher attempting to utilize servlet2.post() - i believe that i searched for a parameterize solution to no avail :( (ended up handling the request by placing a "fake" doPost() in servlet2 that simply called servlet2.doGet())
    however, if your application is functioning correctly on your pc/webserver then the problem may be external to servlet communication (e.g. client webserver's ports not configured or blocked, missing runtime classes, etc.)
    my suggestion would be to set aside the programmatic concerns for the moment - what is the response if you open a browser on a client's machine and access the URL in question (i.e. http://clientserver:port/stefanoServlet)? If it will not respond to access in this manner then it certainly won't when your application calls for it.
    It's possible that there is a coding error but, given the info supplied, i'd start examining the environment, first. Let us know if you have any luck with the test i recommended or not (please provide abundant detail). Or, if you've found the solution then you may want to post back with a quick blub so the next person knows how to escape the trap.
    D

Maybe you are looking for

  • New OS X Mavericks Crashes daily

    Hello, Since upgrading to Maverick my Macbook as crashed almost daily, often in safari. In the year i owned it before upgrading it had only crashed once, i copied the etre check below, any help would be appreciated. Thanks Jeff Hardware Information:

  • RFC error when sending logon data

    Hi; We cannot configure the STMS of our development system. When we try to configure it, system gives an error message: Errors during distribution of tp configuration; TMS Alert Viewers tells us RFC_COMMUNICATION_FAILURE: RFC communications error wit

  • Same songs repeat in shuffle mode

    I have my playlist set to shuffle but I'm hearing the same songs over and over, while other songs never get played at all. There are about 250 songs on the list and I'm hearing the same 100 all the time (roughly). I am thinking there is some smart se

  • Help with Graph

    Hi All In a report i have field called "CERTIFY" and it has two values 1 and 2. Based on this i create a calculation: CASE WHEN DW_MDSS_ROUTE_SO_POST.CERTIFY = '1' THEN COUNT(DW_MDSS_ROUTE_SO_POST.CERTIFY) WHEN DW_MDSS_ROUTE_SO_POST.CERTIFY = '2' THE

  • Weird error in default log

    Any idea what this is. In checking with colleagues who might run reconstruct, no one had... Does it run automatically? It seems to have failed, perhaps crashing and the restarting the store? We are running 6.3-5.02. (120228-25/Solaris Sparc). [12/Jun