Results 1 to 8 of 8
  1. #1
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default POST information to html form via java?

    I've been trying to work this out for a while now but cant seem to do it. I've downloade various different source codes but none seem to work ann they all use slightly different techniques. Basically im at a total loss

    Could someone point me in the right direction or show me some proven source code they've used to get this to work.


    What im trying to do is use a search engine which is similiar to google.
    And im trying to use the POST method to send information to that form via a form that ive made in java, and then display the results.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    There are sample code bits on the forum. To do a POST requires calling a set method before outputting the text of the post data. I forget the method name. Do a Search here for URLConnection or POST

  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    I think you have to use the GET method because of the action name on the form. I tried using POST and I get HTML error 405. HTTP Error 405 Method not allowed Explained
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    It depends on what the server wants to receive: GET or POST.
    You can't assume it will accept either one. Look in the HTML that you are using for your source of <FORM contents.

  5. #5
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    I have looked @ that. What would you send if the action name is "/search" via POST? This is what I came up with and I'm getting an exception:

    Java Code:
    		GoogleOut.write("hl=en&source=hp&ie=ISO-8859-1&q=Java+Tutorials&btnG=Google+Search");
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    I'm not sure what the GoogleOut.write() method does. Its arg looks like a query string.
    What I was talking about is in the HTML file loaded into a browser. The <FORM tag defines if the query is a GET or a POST by its METHOD= attribute.
    <FORM ACTION="http://127.0.0.1:8081/Test_Upload" METHOD=POST ENCTYPE="multipart/form-data">

  7. #7
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Yes that's what I'm talking about too. For my <form tag I have this:

    Java Code:
    <form action="/search" name=f onsubmit="google.fade=null"><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap>
    I was told that if no method attribute is there, I was to assume its method is GET.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  8. #8
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    thanks for the reply guys, i was using google as a quick example, the form that i will be posting to using POST method.

    I will read over whats been wrote in next few days, ive just been preoccuppied last few days.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

Similar Threads

  1. where to post questions about javascript in html?
    By iansane in forum Forum Lobby
    Replies: 2
    Last Post: 05-26-2010, 04:12 PM
  2. Replies: 10
    Last Post: 08-12-2009, 04:02 PM
  3. Replies: 1
    Last Post: 08-05-2009, 02:43 AM
  4. Help in reading values from html form in java
    By ichkoguy in forum Advanced Java
    Replies: 7
    Last Post: 03-16-2009, 07:45 AM
  5. add information to HTML file
    By newbieal in forum New To Java
    Replies: 2
    Last Post: 10-03-2008, 08:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •