Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Saturday, March 26, 2011

Application Ecosystem for the BlackBerry PlayBook

According to their press release, RIM has officially announced the ecosystem for applications that will run on the PlayBook tablet. Below is a quote from the release:
  • BlackBerry PlayBook to support BlackBerry Java and Android apps
  • Native C/C++ development support added, in addition to HTML5, Flash and AIR support
  • Support from leading game engines: Ideaworks Labs (AirPlay) and Unity Technologies (Unity 3)
  • BlackBerry PlayBook becomes a new market opportunity for all the developers who have already created over 25,000 BlackBerry Java apps and more than 200,000 Android apps 
The most important part for me, and something that I've been hoping for a long time, is the added support for Android. What RIM was lacking was an application ecosystem. This will not be the case anymore. And it is not only about Android in the end. Moving away from Java ME is the first step (still need it for existing applications). When you can write applications using HTML, Flash, C/C++, Java ME, and Android, you can't go wrong. There is no other ecosystem out there that provides such a diversity. 

Friday, August 21, 2009

Invoke a Web Service from JSP

This tutorial is a small example on how to call a SOAP-based Web Service from a browser-based client (using HTML and JSP). As an application server, we will use GlassFish. When you download GlassFish, make sure you use the preview version for this tutorial.

The example takes a number as its input and computes the corresponding Fibonacci number. We will start with the Web Service:
package blog.webservice;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class FibonacciNumber {

@WebMethod
public int fibNum(int n) {
int first = 1, fib = 1;
for (int i = 3; i <= n; i++) {
int temp = first + fib;         
first = fib;         
fib = temp;         
}     
return fib;     
}
}

After compilation of the above code, you take the resulting class file and copy it to the blog/WEB-INF/classes/blog/webservice directory. Next step is to package the WEB-INF directory into a WAR file for deployment by executing the following command:
% jar cvf fib.war WEB-INF

The WAR is then copied to GLASSFISH_HOME/domains/domain1/autodeploy, where GLASSFISH_HOME points to the GlassFish install directory. If the deployment succeeds, a second file named fib.war_deployed appears in a few seconds in the autodeploy directory.
The good part about GlassFish is that you do not need to manually (using wsgen) generate the JAX-B artifacts that the service requires, because the current Metro web services stack release ships with GlassFish, automatically generating these artifacts. The WSDL file is also automatically generated and will be used on the client side as described in one of the sections below.

To generate the client-side artifacts (client.FibonacciNumber, client.FibonacciNumberService, etc), we will use wsimport on the wsdl file generated aytomatically by GlassFish:

wsimport -keep -p client http://localhost:8080/fib/FibonacciNumberService?wsdl

Next step is writing the client-side code, namely the HTML page, two JSP pages, and one xml configuration file.

The HTML page is simple and straightforward:
<html>
<body>
<form method = 'POST' action = 'fib.jsp'>
Input number for Fibonacci: <input type = 'text' name = 'inputNumber'><br/><hr/>
<input type = 'submit' value = ' Get Fibonacci '/>
</form>
</body>
</html>

The actual JSP that will invoke the FibonacciNumber web service is below:
<%@ page errorPage = 'errors.jsp' %>
<%@ page import = "client.FibonacciNumber" %>
<%@ page import = "client.FibonacciNumberService" %>
<html>
<body>
<%! private int fibNo, temp; %>
<%
String inputString = request.getParameter("inputNumber");
if (inputString != null) {
temp = Integer.parseInt(inputString.trim());
}

FibonacciNumberService service =  new FibonacciNumberService();
FibonacciNumber port = service.getFibonacciNumberPort();
fibNo = port.fibNum(temp);

%>
<p>fib(<%= temp %>) = <%= fibNo %></p>
<a href = 'index.html'>Try another number</a>
</body>
</html>

Of course, clients should not see such messages displayed in the browser. Consider this error page more for the developer.

The web.xml deployment document is:
<?xml version = '1.0' encoding = 'UTF-8'?>
<web-app xmlns = 'http://java.sun.com/xml/ns/javaee'
xmlns:xsi = 'http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation = 'http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd'
version = '2.5'>
<error-page>
<exception-type>java.lang.NumberFormatException</exception-type>
<location>/errors.jsp</location>
</error-page>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

Any input to the HTML that is not a number will be caught and an error message will be displayed through the errors.jsp page.

Once we have all the files, we package them into a WAR:
jar cvf fibClient.war *.html *.jsp WEB-INF

and deploy it the same way as we did with fib.war.

For testing, open the http://localhost:8080/fibClient/ URL in your favorite browser.

Wednesday, May 20, 2009

From HTML to XHTML

XHTML, or eXtensible HTML, is considered to be the evolution of HTML. I believe that the biggest difference between these two is that XHTML is XML, while HTML is, well, HTML. Other noticeable differences are that XHTML can be extended to include new markup (i.e. elements for vector graphics are already available); XHTML is the language of choice for browsers on mobile devices; data written in XML can be easily transformed into XHTML. Do remember that XHTML is backwards compatible with HTML.

How to convert from HTML to XHTML:
- Change the DOCTYPE to (Strict) XHTML.  For example:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

would become

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

- The <html> opening tag needs new attributes: xmlns, lang,
and xml:lang. For example:

<html>

would become

<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
lang="en">

Why do we need both lang and xml:lang? Because depending on
how the XHTML is interpreted by the browser, either of them
might be needed, hence it is considered a best practice to
include both.

- There must be a matching closing tag for any opening tag.
This implies that if you have empty elements, the tag must
end with />. For example:

<br>

would become

<br />

Why do we need a space before the slash? Because older
browsers cannot recognize "/>" without that space.

- All elements must be in lowercase.
- Attribute values must be in between double quotes and have a
value.
- All special characters must be converted into entities.
For example:

& should be &amp;.

Tuesday, May 27, 2008

Ericsson's Mobile Front Controller

Mobile Front Controller developed by Ericsson is a web application framework that allows you to develop applications that have the same UI logic for both the web and the mobile browser. When the Mobile Front Controller receives a HTTP Request, it detects whether is a wap- or a web- specific request and loads the underlying user interface using the correct HTML, WML, or XHTML-MP markup language. The framework runs directly in a Java EE web container.