?
Solved

Creating a <form> element

Posted on 2002-04-29
13
Medium Priority
?
189 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
[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
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 800 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 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