Solved

Write a java program to POST a form to php3

Posted on 2000-02-14
4
242 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 200 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 45
Tomcat: Unable to run tomcat service. 2 24
jmss example java 2 24
restrict decimal places for double datatype 10 22
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

821 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