Solved

Write a java program to POST a form to php3

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

759 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

22 Experts available now in Live!

Get 1:1 Help Now