Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Mobile Flash Development for PocketPC


Sending Form Data to a JSP

Now since the formula for converting Fahrenheit to Celsius is a matter of simple arithmetic, we were able to perform the conversion within the application. However, let's look at the code that we would use to let a server perform the calculation for us.

In version 1.2 of the Temperature Converter, we're going to instruct the Flash movie to send the Fahrenheit value to a remote JSP server, perform the calculation on the server-side, and return the value back to the Flash movie (for this example, I used the Jakarta Tomcat 5.0.19 as the JSP engine). Following is the ActionScript code that sends the Fahrenheit value to the Tomcat server, and gets the Celsius value back:

function tempConverter(){
     loadVariablesNum("http://localhost:8080/convert.jsp?ftemp=" + fvalue, 0);
}

Listing 1 shows the JSP code that accepts the Fahrenheit value to perform the conversion.

<%
String ftemp = request.getParameter("ftemp");
int f_int = Integer.parseInt(ftemp);
double cvalue = (f_int - 32) * 5 / 9;
out.println("cvalue="+ cvalue);
%>

Listing 1: convert.jsp

So, if you enter "212" as the Fahrenheit value, then the URL String that would be sent to convert.jsp would look like this:

http://10.0.1.15:8080/convert.jsp?ftemp=212

After this is executed, the JSP will return a plain text file like this:

cvalue=100.0 

Since our Flash movie has defined cvalue as a variable, all the JSP had to do was to return a name-value pair for cvalue without any HTML formatting. Of course, if we wanted the JSP to return more than one value back to the movie, then the values must be separated by ampersands. Figure 8 shows the final version of the Temperature Converter application.

Figure 8: Temperature converter running on an iPAQ 4155

Conclusion

So, what can we take away from all this? As you can recall from Table 2, Flash carries over several good features from Java, including platform independence. On the PocketPC platform, Flash applications have a distinct advantage over Java 2 Micro Edition (J2ME) Connected Device Configuration (CDC) applications because Flash can be executed locally or provisioned over a network connection. We've also learned that Flash movies have the capability to load external data, either from a property file or via a URL. One of the most powerful features that we've seen is the capability of Flash to send and receive data from a JSP.

Now that you know that Flash has several mobile and enterprise features built-in, who knows, maybe it will be the platform of choice for your next project!


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.