When the user presses the button
the applet requests the server-side script specified by the parameter "save"
and sends the image data to it.
<applet code="Painter.class" archive="painter.jar,res.zip" width="800" height="600">
<param name="save" value="save.php">
<param name="jnlp_href" value="plugin2.jnlp">
<param name="codebase_lookup" value="false">
</applet>
The request looks as if it's made by the following HTML form:
<form method="post" action="save.php" enctype="multipart/form-data" >
<input type="file" name="image">
</form>
You have to create your server-side script that receives the uploaded file and saves
it on the server (to a file, database, etc.)
Output of the saving script (please read this carefully)
Since your save script on the server is requested by the applet the script response (output) is returned to the applet (not to the browser!). The applet can neither parse HTML nor display it. Therefore YOU SHOULD NOT OUTPUT HTML in your response. Instead, you can output control commands which allow redirecting the browser to another page or displaying a popup message, or execute JavaScript on the applet's page. The commands are sent as#COMMAND=parameter.
Example 1
#SHOWDOCUMENT=some_page.html
After receiving such response the browser loads some_page.html.
Example 2#SHOWMESSAGE=Can't save the image
After receiving such response the editor shows the popup message "Can't save the image".
If more then one command is sent they should be separated by new line characters ("\n" or "\r\n").
Here is the list of supported commands:
| Command name | Editor's action |
|---|---|
#SHOWDOCUMENT |
The editor asks the browser to load a new document. The command parameter isthe document URL (either absolute or relative to the save script). |
#SETDOCTAG |
Specifies the name of the target frame to load the document specified by #SHOWDOCUMENT.Use this command to open new page in a frame or iframe different
than the current one.
|
#SHOWMESSAGE |
The command parameter is displayed as a popup message. |
#SHOWSTATUS |
The command parameter is displayed in the browser's status line. |
#JAVASCRIPT |
The parameter is a JavaScript statement(s) to be executed (with eval())
in the context of the current editor's page. To use this command the developer should set the
<applet> attribute mayscript. Otherwise the applet can't communicate
with javascript. |
Note: Each response line that can't be treated as a valid command is sent to the Java Console.
You can extract the image data in JavaScript. Then you can assign the obtained data to a hidden field of HTML form and submit it to the server.
Here is an example:
<!-- The applet -->
<applet name="painter_applet" code="Painter.class" archive="painter.jar,res.zip" width="800" height="600">
<param name="jnlp_href" value="plugin2.jnlp">
<param name="codebase_lookup" value="false">
</applet>
<!-- The script that extracts the image data -->
<script language="javascript">
function attachImage() {
// copy the image data to the hidden form field "image"
document.saveform.image.value = document.applets["painter_applet"].getBase64Image("format:png");
return true;
}
</script>
<!-- HTML form -->
<form name="saveform" action="save.php" method="post" onsubmit="return attachImage();">
<input type="hidden" name="image">
<input type="submit" value="Save">
</form>
When the user presses the form button "Save" the script extracts the image data
from the applet and assigns them to the hidden field "image".
Then the form fields are sent to the server.
The image data are encoded with the BASE64 method, so you have to decode them on the server (if you like have the image in usual binary form).
When the user presses the buttons "save" the applet requests the script specified by the parameter "save" and sends the image data to it. The request is the standard POST request (not upload!). The image is encoded by the BASE64 method and included in the request as a text field "image", i.e. the request looks as if it's produced by the following HTML form:
<form method="post" action="save.php" >
<input type="text" name="image">
</form>
To activate this saving method include the option method:BASE64
in the applet parameter save_options,
for example:
<applet code="Painter.class" archive="painter.jar,res.zip" width="800" height="600">
<param name="save" value="save.php">
<param name="save_options" value="method:BASE64">
<param name="jnlp_href" value="plugin2.jnlp">
<param name="codebase_lookup" value="false">
</applet>
Upon receiving the image on the server your script may respond using the response commands.