Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Write a java program to POST a form to php3

Posted on 2000-02-14
4
Medium Priority
?
254 Views
Last Modified: 2008-03-17
I want to write a java program to
automate my search over a website.
The html code of that webpage something
like this:

<form method="POST" action="the_items/list.php3">
     
<select size="1" name="class" style="font-size: 9pt">
            <option value="%">All</option>
            <option value="A">Act1</option>
            <option value="B">Act2</option>
            <option value="M">Misc</option>
</select>
<select size="1" name="category" style="font-size: 9pt">
            <option value="%">All</option>
            <option value="c1">category1</option>
            <option value="c2">category2</option>
            <option value="OT">Others</option>
</select>
<select size="1" name="idate" style="font-size: 9pt">
            <option value="100000">No Limit Date</option>
            <option value="1">Today/Yesterday</option>
            <option value="7">Last Week</option>
            <option value="30">Last Month</option>
</select>
<input type="text" name="keyword" size="20" style="font-size: 9pt">

Can some one give me a simple example
java code on how to submit this form to
the server and get search answer from
the server.

I have tried the code like those given
in http://www.javaworld.com/javatips/f_jw-javatip41.html
and
http://www.javaworld.com/javatips/f_jw-javatip34.html
The result are negative. Where should
I specify
action="the_items/list.php3
in the java program?
         
0
Comment
Question by:oatnusigma
4 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 2518283
Java world tips are the best available (and they work)

>> action="the_items/list.php3"

"the_items/list.php3" is part of the url.
in Java you need the full URL - that is
http://www.yourserver.com/main/the_items/list.php3
0
 

Accepted Solution

by:
Tikshya earned 600 total points
ID: 2518498
Hi,

Here is sample code of how u can do it ...

URL currURL = this.getCodeBase();

URL destURL = new URL(currURL.getProtocol(), currURL.getHost(),
currURL.getPort(), "the_items/list.php3");

URLConnection urlConn = destURL.openConnection();

urlConn.setDoOutput(true); // we need to write
 urlConn.setUseCaches(false);    // get info fresh from server

urlConn.setRequestProperty("Content-type", "application/octet-stream");

String request = "inputData=" + "****" // form the request string this way in the same format

Open dataoutputstream and send the output

 outStream.writeBytes(request);
0
 

Author Comment

by:oatnusigma
ID: 2521559
Hi, Thanks for replying to my questions.
There are still two places I don't
understand very well.
(1). I want to run the program as a
java application. However, getCodeBase()
is the member function of Applet class.
(2). Isn't it true that getCodeBase()
gets the URL address of the current
applet, which in this case, is my own
url address. But the date I want to
search is in the website have some
different URL address from where the
applet is stored. Why in all the
examples about POST method using
getCodeBase() method? Why can't I just
specify the URL address directly in the
following statement:
URL destURL = new URL("http://www.xyz.com/the_items/list.php3");
Please comment and Thanks in advance.


0
 
LVL 1

Expert Comment

by:rainmal
ID: 2521652
Yeh you can use it like that.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question