Solved

Creating a <form> element

Posted on 2002-04-29
13
185 Views
Last Modified: 2010-03-31
In an HTML form, an element of that form will be included in the parameter list to the server when submit is pressed.

Like this:

<form>
<select name="selection">
<option>Choice A</option>
<option>Choice B</option>
<option>Choice C</option>
</select>
<input type="submit" value="submit">
</form>

When the user hits the Submit button, the server gets:
selection=Choice A (depends on the users choice)

Now to the question:
How do I write an applet that I can include in a <form> whose value is included in a submit?

-LJJ
0
Comment
Question by:lar_jens
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 6977441
What do mean by the 'value' of the applet?
0
 
LVL 35

Expert Comment

by:girionis
ID: 6977443
 Hmmm... I am not sure if you can do this, to include an Applet in your Servlet form. If you have data in your Applet that you need to pass it in the Servlet/JSP page, you can do it by creating a URLConnection, calling the Servlet through this URLConnection and passing the data to the Servlet using POST or GET. Then you can have a hidden field in your form that contains the values passed by the Applet.

  I am not sure if this is what you are asking though.
0
 
LVL 1

Author Comment

by:lar_jens
ID: 6977467
Well.. I want to be able to do something like:

<form method="post" action="url...">
<applet name="appletName" code="..."></applet>
<input type="submit" value="submit">
</form>

When submit is pressed I get:
appletName=result of user interaction with applet

-LJJ
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:girionis
ID: 6977496
 I see... But how will you send the values of the Applet (I guess you will have JTextField or something like this) to the server? I guess you need a means of communication and this can only be done with HTTP (if you want to talk to Servlet/JSP), via TCP/IP - sockets - if you want to talk to some application and via SMPT if you want to talk to a mail server. It is that simple, just put the applet tag within the form. You cannot just do it.

  Maybe someone else who has more experience can help us more.
0
 
LVL 35

Expert Comment

by:girionis
ID: 6977500
> It is that simple, just put the applet tag within
the form.

 Sorry I meant: It is *not* that simple.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 6977502
Let's say the applet contained a TextField. You could get its contents by writing a public method, say getUserInput() and then calling that from JavaScript before the form is submitted. Something like document.applets[0].getUserInput(). You could then assemble the form's query string yourself.
0
 
LVL 1

Author Comment

by:lar_jens
ID: 6977537
CEHJ

I have begun to think like this myself..
Going to test a few things, and then get back here with the obtained results..

:)
0
 
LVL 1

Author Comment

by:lar_jens
ID: 6977541
Another challenge:

I am using AWT with jdk1.1
0
 
LVL 4

Expert Comment

by:pellep
ID: 6977608
Maybe this could work:

<script language="JavaScript">
function onSubmit() {
document.form1.input1=document.MyApplet.getWhatever();
document.form1.action="/bla.jsp"
document.form1.submit();
}
</script>

.
.
.
<applet name="MyApplet" code="..."></applet>
<form name="form1" action="javascript:onSubmit()">
<input type="hidden" name="input1">
<input type="submit">
</form>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6977813
That was what I was getting at pellep. But I wouldn't call form1.submit() in the submit handler itself.
0
 

Expert Comment

by:aKa
ID: 6979900
1. create a raw socket connection to the web server where the servlet and the applet resides. (port 80 for http usually). Note: this will not work if the web server is not on the same machine where the applet originated due to the applet security restrictions

2. Follow the http protocol. (if POST is used)

 String hostName  ="127.0.0.1";
 int hostPort = 80;
 Socket sock;
try
          {    
               sock = new Socket(hostName, hostPort);
               System.out.println("connection ok");
               String RETURN = "" + (char)13 + (char)10;
               
               InputStream input;
               OutputStream output;
               input = sock.getInputStream();
               output = sock.getOutputStream();
               
               
               //String contentData = "WCI=invite&WCE=invForm&txtScreenName=ipc2002&txtPhoneNum=0123609742";
               String contentData = "file=&handphone=123";
               
               System.out.println("Starting to send username and password");
               Thread.sleep(2000);
               output.write( ("POST /servlet/Cropper? HTTP/1.0" + RETURN).getBytes() );
               output.write( ("From: asdsd@sadfd.com" + RETURN).getBytes() );
               output.write( ("User-Agent: HTTPTool/1.0" + RETURN).getBytes() );
               output.write( ("Content-Type: application/x-www-form-urlencoded" + RETURN).getBytes() );
               output.write( ("Content-Length: " + contentData.length() + RETURN).getBytes() );
               output.write( (RETURN).getBytes() );
               output.write( contentData.getBytes() );
               output.write( (RETURN).getBytes() );
               
               Thread.sleep(5000);
                             
          }
          catch(Exception e)
          {
               System.out.println(e);
          }


if this doesn't work mail me. I copied and pasted this late at night...might have missed some details...

0
 
LVL 2

Expert Comment

by:coreyit
ID: 6985282
aKa, welcome to Experts Exchange. For suggestions on posting comments vs. answers, take a look at the bottom of this page (and related links).

-corey
0
 
LVL 1

Author Comment

by:lar_jens
ID: 7308423
The comment by CEHJ/pellep provides a better solution to me.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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.

713 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