Solved

Creating a <form> element

Posted on 2002-04-29
13
182 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
Comment Utility
What do mean by the 'value' of the applet?
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 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
Comment Utility
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
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 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
Comment Utility
> 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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:lar_jens
Comment Utility
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
Comment Utility
Another challenge:

I am using AWT with jdk1.1
0
 
LVL 4

Expert Comment

by:pellep
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The comment by CEHJ/pellep provides a better solution to me.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

728 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

14 Experts available now in Live!

Get 1:1 Help Now