Solved

Write a java program to POST a form to php3

Posted on 2000-02-14
4
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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:
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

627 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