How choose between post and get when calling a servlet from a java class ??

Hi !!
I have an urgent question : in fact some java programs that call servlets are published on the web, and the principle is to make an url.openconnection() to reach the servlet.
What I don't understand is how we choose if we want to call the get or the post method on the servlet ?????
please answer very fast.....
thanks...

from the URL documentation of openConnection():
"If for the URL's protocol (such as HTTP or JAR), there exists a public, specialized URLConnection subclass belonging to one of the following packages or one of their subpackages: java.lang, java.io, java.util, java.net, the connection returned will be of that subclass. For example, for HTTP an HttpURLConnection will be returned, and for JAR a JarURLConnection will be returned."
Obviously, in case of a http servlet, normally an instance of HttpURLConnection will be returned. If you don't change the request method, GET is the default.

Similar Messages

  • How does iPad choose between wifi and 3G when both are 'on'?

    Easy peasy question.
    I have 02 and Wifi going on my iPad. I know I can use 02 out and about and I know I can use wifi at home etc.
    But when I'm at home how do I make sure I'm using my wifi for data and not my cellular connection???
    I've been turning my cellular to 'off' when at home, just in case, but I don't want to have the faff of turning it off and on, so it would be nice to know how the iPad chooses between wifi and 3G when both data access points are active.
    Also I've had no wifi troubles at home at all. so far... The acid test will be setting it up at work as they have proxyies for everything, but obviously I don't have proxies at home. I'm not sure if the settings screen can cope with different proxies dependent upon different wifi networks... * grin *

    In the status bar I have
    a signal strength indicator then 'O2-UK' then the 'fan' No mention of 3G.
    I'm guessing you're going to say that when 3G is showing then 3G is being used for data?

  • Calling a servlet from a Java Stored Procedure

    Hey,
    I'm trying to call a servlet from a Java Stored Procedure and I get an error.
    When I try to call the JSP-class from a main-method, everything works perfectly.
    Java Stored Procedure:
    public static void callServlet() {
    try {
    String servletURL = "http://127.0.0.1:7001/servletname";
    URL url = new URL(servletURL);
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestProperty("Pragma", "no-cache");
    conn.connect();
    ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
    Integer client = (Integer)ois.readObject();
    ois.close();
    System.out.println(client);
    conn.disconnect();
    } catch (Exception e) {
    e.printStackTrace();
    Servlet:
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    Integer id = new Integer(10);
    OutputStream os = response.getOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(id);
    oos.flush();
    oos.close();
    response.setStatus(0);
    Grant:
    call dbms_java.grant_permission( 'JAVA_USER', 'SYS:java.net.SocketPermission','localhost', 'resolve');
    call dbms_java.grant_permission( 'JAVA_USER','SYS:java.net.SocketPermission', '127.0.0.1:7001', 'connect,resolve');
    Package:
    CREATE OR REPLACE PACKAGE pck_jsp AS
    PROCEDURE callServlet();
    END pck_jsp;
    CREATE OR REPLACE PACKAGE BODY pck_jsp AS
    PROCEDURE callServlet()
    AS LANGUAGE JAVA
    NAME 'JSP.callServlet()';
    END pck_jsp;
    Architecture:
    AS: BEA WebLogic 8.1.2
    DB: Oracle 9i DB 2.0.4
    Exception:
    java.io.StreamCorruptedException: InputStream does not contain a serialized object
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java)
    The Servlet and the class work together perfectly, only when I make the call from
    within the database things go wrong.
    Can anybody help me.
    Thank in advance,
    Bart Laeremans
    ... Desperately seeking knowledge ...

    Look at HttpCallout.java in the following code sample
    http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/jwcache/Readme.html
    Kuassi

  • How to get properties of a bean from another java class

    Hi,
    I am new to JSF. Currently I am facing a problem, and hope you experts can give me some guidance.
    The JSF app i am working on has one Java class for handling a tree structure, MyTreeNode.java, and it also has a bean, NameBean.java, which has two properties, username and password.
    I can easily associate an input text with the #{name.username} to store the user's login... but later on, I need to fetch that information inside of MyTreeNode.java. How do I do that? Thanks!
    -- Jim

    <managed-bean>
         <managed-bean-name>Person</managed-bean-name>
         <managed-bean-class>demo.PersonBean</managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
         <managed-property>
              <property-name>bank</property-name>
              <property-class>demo.BankBean</property-class>
              <value>#{bank}</value>
         </managed-property>
    <managed-bean>
    <managed-bean>
         <managed-bean-name>bank</managed-bean-name>
         <managed-bean-class>demo.BankBean</managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
    <managed-bean>this version doesnt work for me.
    does the single beans have to look any special?
    some demo code out there?
    thx!

  • Calling Servlet from a java class

    Hi,
    I don�t know what I�m doing wrong...
    I try to call a servlet located in a tomcat webserver, from a class, and capture its output. I use an URLConnection object... Everything is all right when I want to get an html page, but, it reports an IOException (FileNotFoundException) when the requested resource is a servlet.
    This servlet is working correctly.
    Can�t I use an URLConnection to access servlets?
    Cheers

    try setting up the user agent property of HTTP protocol to a browsers,its worth a shot.
    Cheers
    Khalid

  • Calling a servlet from a java program

    I could not find a forum for servlet hence am posting
    here
    I have a servlet that accepts prameters and
    gives some out put .
    I want to be able to call this servlet ( invoke )
    from a Java Program .
    How do i do that ..
    Any sample code /pointer would be appreciated.
    Deepa

    hi
    you can try this code.
    URL url = new URL("http://localhost:8888/yourServlet?param1=value1");
    URLConnection con = url.openConnection();
    StringBuffer sBuf = new StringBuffer();
    BufferedReader bReader = new BufferedReader(
    new InputStreamReader(
    con.getInputStream()));
    String line = null;
    while((line = bReader.readLine()) != null) {
    sBuf.append(line);
    System.out.println(sBuf);
    hope this helps
    Shrini

  • Calling a servlet thru'  a Java class

    Hi,
    How can I write a Java class that calls/invokes a servlet?
    Thnks

    I blv you can do some thing like this to invoke a servlet
    URL test = new URL(myURL);
    where myURL should contain the complete URL of your servlet
    test.openStream();
    check more docs on the URL class

  • How do I change or access the setProperty of useBean from the Java class?

    I'm learning JSP beans. Let's say I've got this JSP:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <title>JSP Page</title>
    </head>
    <body>
         <h1>Hello World!</h1>
         <jsp:useBean id="b" scope="page" class="consumidor.BuscaItems">
              <jsp:setProperty name="b" property="what" value="something"/>
         </jsp:useBean>
         <p><jsp:getProperty name="b" property="what"/></p>
    </body>
    </html>And this BuscaItems.java class :
    package consumidor;
    public class BuscaItems {
         public String what="Not defined";
         //Constructor
         public BuscaItems(){
              what="THIS IS WHAT I WANT";
         public void setWhat(String a){
              what=a;
         public String getWhat(){
              return what;
    }But the website returns "something" and not "THIS IS WHAT I WANT", Is this possible?

    I'm sorry for my ignorance about what a constructor is. Thank you for clarifying me the things.
    package consumidor;
    public class BuscaItems {
         public String what="Not defined";
         //Constructor
         public BuscaItems(){
         public void setWhat(String a){
              // Imaginary process to get what I want
              String result="This is what I want";
              what=result;
         public String getWhat(){
              return what;
    }

  • How to give Username and password when calling HTTP page?

    I have this code when i run this I get credentials error. How to give credentials .The authentication is set to windows in the https page. Means pop up will appear to get the credentials
    declare
    req UTL_HTTP.REQ;
    resp UTL_HTTP.RESP;
    value varchar2(1024);
    p_url varchar2(4000);
    OPT varchar2(1000);
    BEGIN
    dbms_output.put_line('');
    p_url:='http://www.xyz.com/';
    dbms_output.put_line(p_url);
    req := UTL_HTTP.begin_REQUEST(p_url);
    utl_http.set_header(req, 'User-Agent', 'Mozilla/4.0');
    resp := utl_http.get_response(req);
    loop
    utl_http.read_line(resp, value, true);
    dbms_output.put_line(value);
    end loop;
    exception
    when utl_http.end_of_body then
    utl_http.end_response(resp);
    END;
    When i run this i get
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <title>401 - Unauthorized: Access is denied due to invalid credentials.</title>
    <style type="text/css">

    Basic authentication is set using the UTL_HTTP.Set_Authentication() call.
    If you are using a proxy and need procy authentication, you can set the username and password for proxy access, as part of the proxy URL. E.g.
    utl_http.set_proxy( 'http://proxyuser:[email protected]', null );NTLM (Windows NT LAN Manager) authentication is proprietary and not part of the HTTP specifications. If that is needed, try and use the username and password as part of the URL - or do some research on how to manually perform NTLM authentication.
    If you are using HTTPS, you need an Oracle Wallet with that server's certificate (making it a trusted certificate), and then set/use the wallet using the UTL_HTTP.Set_Wallet() call. See sample code in {message:id=10820182}.

  • How to pass a "object" as a prameter from one java class to another java

    hi experts, I want to know "How to pass and get object as a parameter from one java class to another java class". I tried follwoing code just check it and give suggetions..
    import Budget.src.qrybean;
    public class ConfirmBillPDF extends HttpServlet
    qrybean db = new qrybean();
    SimplePDFTable pdfTable = new SimplePDFTable();
    pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");
    }Here i want to pass db with simplePDFTableShow method. simplePDFTableShow is in another java class. So how can i do this.
    And also i want to know, how this obj will get.
    please help me.
    Edited by: andy_surya on Jul 14, 2010 7:51 AM

    Hi andy_surya
    what is this i am not understand
    pdfTable.simplePDFTableShow("2010","2011","1","2","1","131","102");but i am try to solve your problem try this
    qrybean db = new qrybean();
    SimplePDFTable pdfTable = new SimplePDFTable();
    pdfTable.simplePDFTableShow(db);and access like this in SimplePDFtable class update your method
    simplePDFTable(qrybean tempDB)
    // write your code
    }

  • Calling another java class from a java class

    Hi Friends,
    I have a class tht works in 2 modes,depending upon which mode i am passing (gui or text) on the command line eg:
    java myclass [mode]
    I want to call this command from another java class,and i wrote this code:
    try
             Process theProcess =
                Runtime.getRuntime().exec("java myclass  "+args[0]);
          catch(IOException e)
             System.err.println("Error on exec() method");
             e.printStackTrace();
          }When i pass "gui" it works fine,but when i pass"text", the class completes and nothing shows up on the command prompt window,so can please somebody tell me how to make this work.
    Thanks

    As aniseed just pointed out, you could do something like this:
    import javax.swing.*;
    class Test extends JFrame {
         public Test(String title) {
              this.setTitle(title);
              this.pack();
              this.setSize(300, 300);
              this.setLocationRelativeTo(null);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) { new Test(argv[0]).setVisible(true); }
    public class Test2 {
         public static void main(String[] argv) {
              Test.main(argv);
    }Run it by executing this command:
    java Test2 "Title of Frame"See if that's not what you're looking for ...

  • I've bought an app called WhatsApp but I was not told that app doesn't work for ipod. So I would like to know how to turn back and get my money back.

    I've bought an app called WhatsApp but I was not told that app doesn't work for ipod. So I would like to know how to turn back and get my money back.

    Did you fail to look at the requirements before purchasing?
    All sales are final.  You can try contacting itunes support and asking for an exception

  • In Mountain Lion how does OS select between ethernet and WiFi when both are activated??

    In Mountain Lion how does OS select between ethernet and WiFi when both are activated??  How does OS use "both" networl accesses??

    It will pick the highest service in the list which has an internet connection.
    To order the list, open Network System Preferences and select Set order of network services from the button below the service list.

  • I downloaded something called MPlayerX and it is ruining my computer (a macbook pro) and now on safari theres pop up adds that shouldn't be there and on the google homepage theres adds. I want to know how to fix this and get rid of MPlayerX :( PLEASE

    I downloaded something called MPlayerX and it is ruining my computer (a macbook pro) and now on safari theres pop up adds that shouldn't be there and on the google homepage theres adds. I want to know how to fix this and get rid of MPlayerX PLEASE HELP ME!!!!

    MPlayerX isn't itself the problem; it was downloaded from a source that packaged adware with it. Click here and follow the instructions, or if desired, run Adware Medic.
    (114466)

  • Let applications choose between WiFi and Ethernet

    Hi Forum,
    So basicly I'm connected to a secure ethernet line with limitations, besides that I'm also connected to wifi with no limitations.
    I want to let apps choose between wifi and ethernet, is there any way to do so ?

    (A repost of something I posted elsewhere - trying to help others)
    If it helps you at least a little, in the Podcast App, playlists are now called "My Stations". You can add entire podcasts to Stations (and create new Stations), or you can add individual episodes to the "on-The-Go" station.
    Not intuitive, and not as good as having the podcasts back with the music, but it gets the job done till Apple listens to the users again and changes this back.
    Cheers!
    Ken

Maybe you are looking for