Solved

Write a java program to POST a form to php3

Posted on 2000-02-14
4
238 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java asynchronous logging 4 50
Unexpected HttpURLConnection connection behavior 2 84
get weblogic logged in user in java 2 57
windows explorer path to command prompt 5 29
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now