Calling servlet through HttpURLConnection

hi guyz ....
I am trying to call a servlet, hosted on Tomcat/4.0.3. It is accepting two parameters. I am using the following program to call it, but it is continuously throwing exception Exception in thread "main" java.io.FileNotFoundException: http://202.141.230.246:8080/examples/servlet/AServlet. When I paste the above same url in browser, it works fine, also other servlets at the same location are working fine from my program and browser. For your convenience, the effective part of the code is given below:
      URL url = new URL("http://202.141.230.246:8080/examples/servlet/JndiServlet");
      URLConnection connection = (URLConnection) url.openConnection();
      //connection.setRequestMethod("POST");
      connection.setDoOutput(true);
      PrintWriter out = new PrintWriter(connection.getOutputStream());
      // encode the message
      String name = "s="+URLEncoder.encode("Qusay Mahmoud");
      String email = "name="+URLEncoder.encode("[email protected]");
      // send the encoded message
      out.println(name+"&"+email);
      out.close();
      BufferedReader in =
                new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String line;
      while ((line = in.readLine()) != null)
         System.out.println(line);
      in.close();Exception is thrown on the line where i am creating an instance of BufferedReader class.
Any help will be of great value.
Raheel.

hi again .... a slight change in code fragment.
plz help !!!!
URL url = new URL("http://202.141.230.246:8080/examples/servlet/AServlet");     
   HttpURLConnection connection = (HttpURLConnection) url.openConnection();     
   connection.setRequestMethod("POST");     
   connection.setDoOutput(true);     
   PrintWriter out = new PrintWriter(connection.getOutputStream());     
   // encode the message     
   String name = "id="+URLEncoder.encode("Qusay Mahmoud");     
   String email = "name="+URLEncoder.encode("[email protected]");     
   // send the encoded message     
   out.println(name+"&"+email);     
   out.close();     
   BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));     
   String line;     
   while ((line = in.readLine()) != null)     
        System.out.println(line);     
   in.close();

Similar Messages

  • Call servlet through stateless sessionbean

    can any body help me about.....
    code to call(run) servlet through stateless session bean,
    how can develop it using URL class..
    please help me............

    Hi
    it can be possible if your session bean  can call servlet through an protocol.
      means you can create an URL or URL connection class and call it through http protocol.
    i .e we can create URLConnetion ( HttpURLConnection ) object to that servlet  from a session bean.
    I hope this will help you some extent to solve your probs.
    Thanks
    Mrutyunjaya Tripathy

  • Hit a servlet through HTTPURLConnection-Strange problem

    Hi!
    i have a servlet deployed on tomcat
    i can connect to it using http://localhost:9696//TTMSDispatcher/ttmsrequestdispatcher"
    on Internet explorer..this servlet gives a hit to a JSP..It works fine when i try it on Internet explorer..my servlet gives a hit to the JSP
    i am trying to give a hit to the servlet from a Java application,but the connection.getResponseCode() gives 404.the following is the code..
    though the servlet is deployed..please suggest a solution
    public void hitUserConnectJsp(){
    String sLogin = "neeraj";
    String sPassword = "neeraj1";
    try {
    String connectionURL = "http://localhost:9696//TTMSDispatcher/ttmsrequestdispatcher";
    StringBuffer sTrBuffer = new StringBuffer(connectionURL);
    sTrBuffer.append("/");
    sTrBuffer.append("?login=");
    sTrBuffer.append(sLogin);
    sTrBuffer.append("&password=");
    sTrBuffer.append(sPassword);
    System.out.println("Connection url="+sTrBuffer.toString());
    URL objUrl = new URL(sTrBuffer.toString());
    HttpURLConnection connection = (HttpURLConnection) objUrl.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.connect();
    int a = connection.getResponseCode();
    System.out.println("Response code="+a);
    } catch (Exception e) {
    e.printStackTrace();
    }

    I think you are missing a connect() call before the getOutputStream

  • Run  servlet through stateless session bean

    can any body help me about.........
    how to run(execute or call) servlet through state less session bean.
    i have developed servlet program, now i want to run that servlet from stateless session bean ,can any body help ,how to write the code for above one

    Hi
    it can be possible if your session bean  can call servlet through an protocol.
      means you can create an URL or URL connection class and call it through http protocol.
    i .e we can create URLConnetion ( HttpURLConnection ) object to that servlet  from a session bean.
    I hope this will help you some extent to solve your probs.
    Thanks
    Mrutyunjaya Tripathy

  • Error while calling servlet in WebLogic

    Hi,
    We are trying to call servlet in WebLogic by using http://scrmskr.apac.nsroot.net:7801/forms/HelloWorldServlet URL and getting
    below error.
    ========================================================================
    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.
    ========================================================================
    Here we are calling HelloWorldServlet servlet which is kept in below path
    /rcrmap2/weblogic/bea/user_projects/domains/frmrep_rcrms/servers/WLS_FORMS/tmp/_WL_user/formsapp_11.1.1/e18uoi/war/WEB-INF/classes
    Entries for HelloWorldServlet in web.xml:
    ========================================================================
    <servlet>
    <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>HelloWorldServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>frmservlet</servlet-name>
    <url-pattern>/frmservlet/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/HelloWorldServlet*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>lservlet</servlet-name>
    <url-pattern>/lservlet/*</url-pattern>
    </servlet-mapping>
    ========================================================================
    HelloWorldServlet.java:
    ===============================================================================
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class HelloWorldServlet extends HttpServlet {
    public void service(HttpServletRequest req,
    HttpServletResponse res)
    throws IOException
    // Must set the content type first
    res.setContentType("text/html");
    // Now obtain a PrintWriter to insert HTML into
    PrintWriter out = res.getWriter();
    out.println("<html><head><title>" +
    "Hello World!</title></head>");
    out.println("<body><h1>Hello World!</h1></body></html>");
    ===============================================================================
    Please share your inputs as to what needs to be done for the same.
    Thanks & Regards,
    Harish

    Hi Jay,
    Please also find forms.conf_ entries
    ========================================================================
    # Name
    # forms.conf - Forms component Apache directives configuration file.
    # Purpose
    # It should include the weblogic managed server (routing) directives for
    # the servers where Forms applications are deployed and other miscellaneous
    # Forms component OHS directives.
    # Remarks
    # This file is included with the OHS configuration under
    # $OI/config/OHS/<OHS Node Name>/moduleconf sub-directory.
    # virtual mapping for the /forms/html mapping.
    RewriteEngine on
    RewriteRule ^/forms/html/(..*) /workaroundhtml/$1 [PT]
    RewriteRule ^/rcrms/html/(..*) /workaroundhtml/$1 [PT]
    AliasMatch ^/workaroundhtml/(..*) "/rcrmap2/weblogic/bea/rcrms/config/FormsComponent/forms/html/$1"
    AliasMatch ^/forms/frmjscript/(..*) "/rcrmap2/weblogic/bea/user_projects/domains/frmrep_rcrms/servers/WLS_FORMS/tmp/_WL_user/formsapp_11.1.1/e18uoi/war/frmjscript/$1"
    AliasMatch ^/rcrms/icons/(..*) "/rcrmap2/weblogic/bea/ORA_PFRD/forms/java/$1"
    # Virtual path mapping for Forms Java jar and class files (codebase)
    AliasMatch ^/forms/java/(..*) "/rcrmap2/weblogic/bea/ORA_PFRD/forms/java/$1"
    # Virtual path mapping for testcrms (codebase)
    AliasMatch ^/rcrms/java/(..*) "/rcrmap2/weblogic/bea/ORA_PFRD/forms/java/$1"
    AliasMatch ^/forms/(..*) "/rcrmap2/weblogic/bea/user_projects/domains/frmrep_rcrms/servers/WLS_FORMS/tmp/_WL_user/formsapp_11.1.1/e18uoi/war/WEB-INF/classes/$1"
    AliasMatch ^/rcrms/(..*) "/rcrmap2/weblogic/bea/user_projects/domains/frmrep_rcrms/servers/WLS_FORMS/tmp/_WL_user/formsapp_11.1.1/e18uoi/war/WEB-INF/classes/$1"
    AliasMatch ^/rcrms/WebCLAuth/* rcrms
    <Location /forms>
    SetHandler weblogic-handler
    WebLogicHost kauh0079
    WebLogicPort 8001
    </Location>
    ========================================================================
    Thanks & Regards,
    Harish

  • Calling servlets from main()?

    Hi
    I would like to know that while calling servlets from another class having main(), how can we set the type of request i.e. put, post or get?
    Thanks

    use the method - setRequestMethod( "POST") of HttpURLConnection for setting the method to POST.Similarly for other methods..
    You could find [url http://java.sun.com/developer/JDCTechTips/2004/tt0210.html#2]this useful

  • Calling servlets in tomcat 4 (path-problem)

    Hi,
    I have copied the IsItWorking-Servlet in webapps/examples/Web-Inf/classes.
    To call the servlet through a browser I have to write:
    http://server-name:8080/examples/servlet/IsItWorking .
    This works fine. But ..unfortunately I have to call the servlets in the following way:
    http://server-name:8080/examples/IsItWorking.
    Which xml-File defines the parameter "servlet" ??

    Hi,
    edit the web.xml under the \examples\web-inf.
    add the following
    <servlet>
    <servlet-name>
    IsItWorking
    </servlet-name>
    <servlet-class>
    IsItWorkingServlet
    </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>
    IsItWorking
    </servlet-name>
    <url-pattern>
    /IsItWorking
    </url-pattern>
    </servlet-mapping>

  • Asp calling servlets

    hello friends.
    i want to call servlets from the asp page ...i dont know how to do it..plz reply me for this problem..
    thanks in advance,
    varun bhatnagar

    use the method - setRequestMethod( "POST") of HttpURLConnection for setting the method to POST.Similarly for other methods..
    You could find [url http://java.sun.com/developer/JDCTechTips/2004/tt0210.html#2]this useful

  • How can I fix my phone's ringer? The call comes through but it won't ring.

    I've had my iPhone for over 6 months now with no issues. I have not had it reserviced, its not refurbished, and I bought it new from an AT&T store.
    This week my phone stopped ringing. The incoming call comes through on the screen, but it doesn't ring out loud so I know I'm getting a call and I can't sit and stare at my iPhone's screen all day long to see if I'm getting an incoming call. It vibrates when a call comes in maybe 20% of the time.
    Today I went into settings and reset my settings but it still didn't bring my ringer back. It plays the ringers when you are looking through the list of ringers, it plays it when you alter the volume setting, but when a call is actually coming in or when I'm receiving a text message or something, no sound.
    What can I do to get my ringer back?

    Check the mute switch on the side above the volume rocker. If the red dot shows, the phone is muted. You'll still be able to play the ringtones to select one.
    I find that the switch can be thrown to "mute" by accident when I put my iPhone in my belt holster.

  • Error while executing servlet through a HyperLink.

    Hi
    When i am trying to execute a servlet through the HyperLink using this statement
    where CallStatusDetailsAssign is my servlet.then i am getting this error :
    The Following is the Alert Message.
    1. Microsoft InterNet Explorer
    http://localhost:8080/examples/servlets/CallStatusDetails?Call_ID=1&EMP_NO=1
    ** Download of the specified Resource has failed.
    & also getting this error:
    2. IE Cannot open the Internet Site
         ** Operation has been Cancelled.
    If i refresh the screen by clicking on refresh button in the Internet Explorer.the Page is getting displayed properly.
    Is there any problem with my servlet code ??or some other Problem.
    Can Anyone Please help me on this & give me the Solution for my Problem.
    Rashmi

    I'm not sure if this is cause of your problem but the anchor tag should look like this:
    some text</ a>
    ... in the code the quotes are missing
    spieler

  • Call RFC through EJB

    Hi,
    I have senerio in which i need to call RFC through EJB.
    Thanks.
    Abhilasha
    Edited by: Abhilasha Dahare on Oct 3, 2008 1:29 PM

    Hi,
    Go through the following links:
    Extract R/3 data via EJB
    http://help.sap.com/saphelp_nw04/helpdata/en/35/42e13d82fcfb34e10000000a114084/frameset.htm
    Siddharth

  • How to call servlets in sunone webserver

    hi,
    I am using sunone web server , I deployed but how to call servlets in sunone webserver any one tell me
    bye

    Typical URL structure is like this:
    http://<myServer>:<myPort>/servlet/<fully qualified class name of my servlet>Unless you have configured a different servlet mapping ...

  • Call Transaction Through RFC

    Hi ,
    I am trying to do a call transaction through RFC call from a Middleware which is a CPIC user (only communication Non dialog User ) . 
    Call  transaction does gets executed without any error but it does not update any data.But when I run it through my user id it works absolutely fine .
    I am not sure what is causing the issue
    Security authorization?
    RFC through Non Dialog user ?
    Paramters missing in RFC  ?
    Paramatertes missing in call transaction option?
    If anyone of you has faced a similiar issue then please let me know the path forward.
    Thanks
    Vikas

    Hi Vikas,
        The problem is in Authorization? And check the mode of Process Synchoronus or asynchoronous? Both the RFC and CALL transaction should be Same /
    Thanks
    MAnju

  • Pass query to servlet through midlet

    Hi, I have a problem here. I would like to control the SQL Statement to be executed by the servlet using the mobile midlet. Like this one:
    midlet -> will call servlet with parameter statement -> servlet will execute the statement parameter passed by the midlet and will return a data result in XML -> midlet will read the XML file and retrieve the data.
    Another thing I would like to ask is how will I make the servlet to output an XML file that can be read by the midlet. If there's some tutorial on how please give me the link.
    I hope you get my point.

    I have made to retrieve data on my midlet from my servlet. The bad thing is the data sent on the midlet has html tags. How will I make the midlet to just output the data result without the tags?If you are in charge of the servlet, then have it output plain text. If you need to parse the MIDlet input first, then having the content of XML/HTML elements will allow you to print them out.
    Is this servlet used from HTML browser as well? If so, try having a separate one for mobile devices. There are plenty options to do it.
    Daniel

  • Calling servlet from a backing bean

    hi guys i need to call a servlet from a backing bean in JSF. how do i do that ?
    The scenario is i have to call servlet on a different machine from my backing bean . I also need to pass an object to the servlet .
    This object contains data which must be manipulated and inserted in the database by the calling servlet.
    I also want that after insertion in the db the control must be passed to the backing bean .
    Is this all possible???
    Please help

    You may want to investigate the built in java.net.URL class. For advanced needs, Apache has a Java HTTP client library.

Maybe you are looking for

  • Itunes 11 repeatedly asking for password

    This seems not to matter if I'm even using iTunes or not.  If the program isn't forcibly quit (it almost never is, since the family uses the AppleTV all day), the password entry window will pop up on the iMac over and over again.  I just had it happe

  • Create Appraisal document using Function Modules

    Hi Everyone, We need to interface directly with the HR appraisals backend. As no BAPI's have been delivered for Appraisals from EhP4 onwards we need to use the function Modules: HRHAP_TEMPLATE_GET_DETAIL - to get template field values Then HRHAP_DOCU

  • Infostructure update routine : debug problem

    Hi All, We have created three update routines for three corresponding infostructures. But I am not able to debug this routine. I tried to put a hard breakpoint also, but it was of no use. The Infostructure logs the changes in the sales order. How can

  • 11.1.3 installation sequence without EPMA architecture

    I'm installing Hyperion Shared services, workspace, essbase Planning and reports in our environment. I installed all components using installtool.cmd. I'm running confuration utility to configure components following sequence: 1. Configure Shared ser

  • Exception error Oxc0000005

    I am getting an exception error Oxc0000005 when I use the image processor in bridge. I'm using CS6 in WinXP. Any suggestions appreciated!