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

Similar Messages

  • How to call a specific method in a servlet from another servlet

    Hi peeps, this post is kinda linked to my other thread but more direct !!
    I need to call a method from another servlet and retrieve info/objects from that method and manipulate them in the originating servlet .... how can I do it ?
    Assume the originating servlet is called Control and the servlet/method I want to access is DAO/login.
    I can create an object of the DAO class, say newDAO, and access the login method by newDAO.login(username, password). Then how do I get the returned info from the DAO ??
    Can I use the RequestDispatcher to INCLUDE the call to the DAO class method "login" ???
    Cheers
    Kevin

    Thanks for the reply.
    So if I have a method in my DAO class called login() and I want to call it from my control servlet, what would the syntax be ?
    getrequestdispatcher.include(newDAO.login())
    where newDAO is an instance of the class DAO, would that be correct ?? I'd simply pass the request object as a parameter in the login method and to retrieve the results of login() the requestdispatcher.include method will return whatever I set as an attribute to the request object, do I have that right ?!!!!
    Kevin

  • Calling a servlet from another servlet?

    Hi
    I would like to know that how can I call one Servlet from another Servlet. I have tried getServlet() method of ServletContext but it has been deprecated. I want to call a specific method of the other Servlet, is there any other way?
    Thanks

    I should have seen it from your previous post :(
    Code of Servlet 1:
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws
    ServletException, IOException
    RequestDispatcher rDispatch = null ;
    rDispatch = getServletConfig
    ().getServletContext().getRequestDispatcher
    ("/Servlet2") ;
    rDispatch.forward(request, response) ;
    System.out.println("Back in 1");
    I assume Servlets 1and 2 are in same web app and you've mapped your servlet2 to /Servlet2 in your web.xml
    make it as
    rDispatch = request.getRequestDispatcher("/Servlet2");
    rDispatch.forward(request,response);
    Nothin's wrong with yer servlet2

  • How to call a Applet from a servlet and vice versa...?

    Hi all
    Can anyone help me how to call a applet from a servlet and vice versa. When the applet is called it should contact the database (oracle8i) and get the data. When i submit the applet form the data in the applet should be saved in the database.
    Thanks in advance
    Kamalakannan

    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

  • Different ways to invoke a servlet from another servlets?

    Hello,
    I am a bit confused today. I was thinking about all the ways by which I can invoke a servlet from another servlets. I know it can be done by creating an instance of the 2nd servlet in the 1st one. Is there any other way? such as say.... RequestDispatcher perhaps?
    Here is an example to illustrate my point. I have a login.jsp which submits to login.do. login.do search through database and first authenticate email and then the corresponding password. Now its time for displayGame.do. So here how do i do? if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets? Can I still go for Redirection or Forward??
    Thank you for reading this confused post. :-)

    if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets?Question: do you know what a JSP becomes when you first run it?
    Answer: a servlet.
    So yes, you can use a RequestDispatcher to forward/redirect to a servlet OR a JSP, whatever you like.

  • HOW TO CALL A FORM FROM ANOTHER FORM

    HOW TO CALL A FORM FROM ANOTHER FORM [local machine]

    Balraj wrote:
    HOW TO CALL A FORM FROM ANOTHER FORM [local machine]The way you asked question is this bit of request or order?
    Secondly, you used capital latters which are being treated as Shouting Language. So, always try to switch off the Capslock of your keyboard.
    Thirdly, you are very lazy to serach on forum or google for your problem instead of waiting someone to anwer your question.
    Your should seriously have a look at FAQ.
    http://wikis.sun.com/display/Forums/Forums+FAQ
    Also here.
    http://www.catb.org/~esr/faqs/smart-questions.html
    Please read documentation for the initial questions.
    -Ammad

  • How to call a process from another project

    Hi;
    How to calling a process from another process in another project? Which activity that i need or web service, direct binding? I use 11g

    Hi Tulasi ;
    I have wsdl of the process i need to call. Also wsdl address on the server. But CALL activity can't use to service call. CALL activity can use only to reusable process call.
    I think, this operation must make on composite.xml. But I have a same problem with this method and it don't work.
    I create a base process that looking at below. It's include a direct binding. Is it include a direct binding?
    [Base Process|http://d1201.hizliresim.com/t/s/21wqu.png]
    Then i create a process that call to base process:
    [Caller Process|http://d1201.hizliresim.com/t/s/21wqx.png]
    I paste to base process' wsdl address on the server. Then i select port type (BaseProcessPortType) and a warning has occured that you see the picture above. Base Process contain Oracle SOA Composite Type. What's the wrong? It happened for Callback Port Type.
    And second question is what's the Address? (under Reference Binding Setails option).
    I think, i create the this direct binding correctly, i call to base process into my caller process via service activities.

  • How to call one .SWF from another?

    How do I call one .SWF from another. I built a very beefy
    base .SWF, and want to add music overlay, and an intro slide show
    to the exsting Flash animation, but put it in a second .FLA/.SWF
    file. How do I call one from the other?
    This will be embedded in an HTML file but I assume this is
    superfluous to my question.
    F.Z.

    I think you should open that Another SWF (FLA),
    and add some actionscript..
    For example, you could create a movie clip, and write
    actionscript in the
    first keyframe:
    loadMovie("
    http://www.somewebpage.com/movie.swf",
    this);
    "FredZimmerman" <[email protected]> wrote in
    message
    news:ftnjas$mj5$[email protected]..
    > How do I call one .SWF from another. I built a very
    beefy base .SWF, and
    > want
    > to add music overlay, and an intro slide show to the
    exsting Flash
    > animation,
    > but put it in a second .FLA/.SWF file. How do I call one
    from the other?
    >
    > This will be embedded in an HTML file but I assume this
    is superfluous to
    > my
    > question.
    >
    > F.Z.
    >

  • How to call a BSP from another BSP?

    Hi All,
    I've created a BSP for hiring new employees.  I have a situation whereby when the user presses a button a pop window will be displayed listing all the positions in the company.  The user selects the correct position, which then populates an input box on the originating page and the pop up window closes.
    This pop up window is a page in another bsp which goes off and gets the positions and stores the selection in a cookie.
    Now my problem is how do i call this 'get postions' bsp from my originating bsp?
    I've tried using the <%@ include file="/sap/bc/bsp/sap/z_hr_org_model"%> but i get the error only page fragments can be included.
    So how do i call one bsp from another??
    Any help would be much appreciated,
    Kind Regards,
    Liz.

    Look at the below [link|http://****************/Tutorials/BSP/F4Help/Tutorial.htm]
    The only difference in your case is, you need to call the popup from different BSP Application.
    To do that, just add the full path when you call the document.open..
    For example,
    document.open("/sap/bc/bsp/sap/z_hr_org_model/main.do", ............)
    Raja

  • How to call WD Application from another WD Appliction

    Hi all,
    how can we call webdynpro application from another wbdynpro application on click of a button in the same browser.
    pls suggest
    regards
    vishal

    Hi Vishal,
    Just try to Embed the another WD Component into Component Controller first.
    And then Create a View and map it to window as U regularly do,
    then in Window- Explore the tree until that View, now open Context Menu for Embed View Option and from the scroll U get search for that WD Component U wanna Embed.
    U also have to handle Plugs here, Because the result application required some parameters to be passed that U do from ur first application by passing  those values through Plugs.

  • How to call one program from another program

    Hai,
      How to call one program through another program.
    Example.
       I have two programs 1.ZPROG1 2. ZPROG2.
    When i execute ZPROG1 at that time it should call ZPROG2.

    Hi ,
    u can use submit statement to call a program .
    DATA: text       TYPE c LENGTH 10,
          rspar_tab  TYPE TABLE OF rsparams,
          rspar_line LIKE LINE OF rspar_tab,
          range_tab  LIKE RANGE OF text,
          range_line LIKE LINE OF range_tab.
    rspar_line-selname = 'SELCRIT1'.
    rspar_line-kind    = 'S'.
    rspar_line-sign    = 'I'.
    rspar_line-option  = 'EQ'.
    rspar_line-low     = 'ABAP'.
    APPEND rspar_line TO rspar_tab.
    range_line-sign   = 'E'.
    range_line-option = 'EQ'.
    range_line-low    = 'H'.
    APPEND range_line TO range_tab.
    range_line-sign   = 'E'.
    range_line-option = 'EQ'.
    range_line-low    = 'K'.
    APPEND range_line TO range_tab.
    SUBMIT report1 USING SELECTION-SCREEN '1100'
                   WITH SELECTION-TABLE rspar_tab
                   WITH selcrit2 BETWEEN 'H' AND 'K'
                   WITH selcrit2 IN range_tab
                   AND RETURN.
    regards,
    Santosh thorat

  • How to call a method from another class

    I have a problem were i have to call a method from another class. What is the command line that i have to use. Thanks.

    Here's one I wipped up in 10 minutes... Cool!
    package forums;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import krc.utilz.io.Filez;
    import java.io.FileNotFoundException;
    class FileDisplayer extends JFrame
      private static final long serialVersionUID = 0L;
      FileDisplayer(String filename) {
        super(filename);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(600, 800);
        JTextArea text = new JTextArea();
        try {
          text.setText(Filez.read(filename));
        } catch (FileNotFoundException e) {
          text.setText(e.toString());
        this.add(text);
      public static void main(String args[]) {
        final String filename = (args.length>0 ? args[0] : "C:/Java/home/src/forums/FileDisplayer.java");
        try {
          java.awt.EventQueue.invokeLater(
            new Runnable() {
              public void run() {
                new FileDisplayer(filename).setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
    Filez.read
       * reads the given file into one big string
       * @param String filename - the name of the file to read
       * @return the contents filename
      public static String read(String filename) throws FileNotFoundException {
        return Filez.read(new FileReader(filename));
       * Reads the contents of the given reader into one big string, and closes the reader.
       * @param java.io.Reader reader - a subclass of Reader to read from.
       * @return the whole contents of the given reader.
      public static String read(Reader in) {
        try {
          StringBuffer out = new StringBuffer();
          try {
            char[] bfr = new char[BFRSIZE];
            int n = 0;
            while( (n=in.read(bfr,0,BFRSIZE)) > 0 ) {
              out.append(bfr,0,n);
          } finally {
            if(in!=null)in.close();
          return out.toString();
        } catch (IOException e) {
          throw new RuntimeIOException(e.getMessage(), e);
      }Edited by: corlettk on Dec 16, 2007 1:01 PM - dang [code [/tags][                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • What is the best way to call a servlet from another servlet?

    I have a project with 9 servlets (class project). The way I have been moving from servlet to servlet is like this
    doPost(...)
    {      response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>Functions</title>");
    out.println(f"<form name=frm6 method=post action=/servlet2");
    out.println("<input type=submit name='btn' value='servlet2'>");
    out.println("</form>");
    So I have these 9 servlets - I call any 8 of them from the first servlet so I have 8 buttons on 8 forms <form=frm1, frm2, ...frm8 method = post...> But when I bring up the first servlet only 6 buttons show up. I was thinking about using hyperlinks instead, but I would like to do this with buttons. I wanted to do this with javascript and the location object, but I was advised to use jsp. I just want to move from one servlet to the next. Any suggestions appreciated for the best/preferred method for moving from one servlet to the next.
    Thanks

    I think you may need some clarification of terminology etc..
    First off, JSP isn't an alternative to javascript, it's an alternative to coding a servlet. A JSP is a mixture of java code and HTML and is translated into a servlet by the system. JSPs are primarilly for generating HTML pages with variable content. JSPs very frequently generate HTML which includes Javascript.
    You probably shouldn't think of what you're doing as one servlet invoking another, that does happen; a servlet can transfer an transaction to another servlet or JSP. In fact it's standard practice that a servlet does the logical stuff (like interpretting form data) then transfers to a JSP to generate the response page. However in this case it's the browser that can invoke one of the 8 servlets, the first servlet merely creates the page from which they are invoked.
    It's not obvious why only some of your buttons are showing up. In a case like this use the "view source" option on your browser to find out what HTML the servlet is actually delivering. What's wrong should be evident from that.
    You can put a hyperlink arround a button, or an image. Mostly people turn up their noses at the buttons supplied by HTML and use their own images for buttons. You
    can do somthing like this:
    <img src="/images/button3.png" border="0">
    (Of course this arrives as a GET transaction not a POST).
    Or you can do a bit of javascript like:
    <img src="/images/button3.png" style="Cursor: pointer;"
    onclick="document.locations.href='/servlet3';">

  • How to Call SQL Loader from Java ( servlet )?

    We need to call SQL Loader command from Java Servlets? Any suggestions how this can be done?
    Thanks
    Rahul

    Probably not the best way, but you could try using JNI to call a C function which then invokes SQL Loader via system() or exec(). I haven't done this myself though...

  • How to call a view from another

    Hello Experts,
            I have embedded a view (let us call this view 'A') in standard homepage. This works fine. Now on click of a button on this embedded view I want to launch another view that is also created by me, in the same component in which I had created view A. But I do not know how to launch this second view
         Could you please tell me how to call/launch a view from another on click of a button?
    Regards,
    Prafful

    Hello Prafful,
    I guess by launching you mean substituting one view by another. It can be achieved by declaring a navigational link in the runtime repository from one view to another. You have to create an event handler on the button and outbound plug in your view using the wizard. Then, on the event handler you call an outbound plug where you trigger a navigation using this navigational link and the view A will be replaced by view B.
    A code which needs to be done in outbound plug:
    me->view_manager->navigate(
    source_rep_view = me->rep_view
    outbound_plug   = 'NAVLINKNAME'
    data_collection = iv_data_collection ).
    Best Regards,
    Yevgen

Maybe you are looking for