Solved

Creating a <form> element

Posted on 2002-04-29
13
186 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss wildfly 10.1 10 609
Html Table Looping (part 2) 5 41
Delphi Firemonkey: if the Sms contain special characters it won't send it 3 82
Java regex 5 21
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 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

734 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