Silverlight animation in Servlets

What if you are a servlet or jsp developer and want to run a silverlight animation on your page..
Here’s the solution..
The silverlight animation is in servlet…
Its very basic and easy..

You need:
Tomcat (i used 5.5) : To run servlets.
Microsoft Blend : To create silverlight animation. Its your choice to use any tool to create SL apps.

Here are the steps:
1) Create a folder to place your files in the directory that Tomcat uses for your class files.
I placed my files here: C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\SilverlightServlet
SilverlightServlet is the folder.. in webapps..

2) Add the folder containing files for your silverlight animation.
My location : C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\SilverlightServlet\SL
SL folder contains another folder named PeopleAnimation with xaml and javascript files necessary to
run the animation..

Follow this diagram to add the necessary files to run servlets with sl animation..
This is my folder structure diagram..

FolderStructure to place files

3) Write java code to host your silverlight files..
Here is the code.. code file code file

4) Edit the web.xml file to do the mapping to let Tomcat locate your class file.
This is the web.xml file..

Web.xml file content

Web.xml file content

5) Finally run your application in localhost

Final animation in Servlet

Final animation in Servlet

Communicating with ports using javax.comm package for Windows

The Java Communications API from Sun available in javax.comm package
provides access to communications resources.It supports configuring,sending and receiving data for parallel and serial ports.

The first step for using this package is placing the proper files
in respective JAVA_HOME’s directory folders.

1) win32com.dll : keep it in JAVA_HOME’s bin directory.
In my case I placed it here C:\Program Files\Java\jdk1.6.0_05\jre\bin

2)comm.jar : place it in JAVA_HOME’s lib\ext directory.
Mine was in C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext

3) : same as above.
So this file goes in C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext

To verify whether the javax.comm.package is installed and operational,
Here is a simple program which prints out the serial and parallel ports.

import javax.comm.*;
import java.util.*;

/** List all the ports available on the local machine. **/
public class ListPorts
public static void main (String args[])

Enumeration port_list = CommPortIdentifier.getPortIdentifiers();

while (port_list.hasMoreElements())
CommPortIdentifier port_id = (CommPortIdentifier)port_list.nextElement();

if (port_id.getPortType() == CommPortIdentifier.PORT_SERIAL)
System.out.println (“Serial port: ” + port_id.getName());
else if (port_id.getPortType() == CommPortIdentifier.PORT_PARALLEL)
System.out.println (“Parallel port: ” + port_id.getName());
System.out.println (“Other port: ” + port_id.getName());
} // main
} // class PortList

Now build and run the program.

C:\>java ListPorts
Serial port: COM7
Serial port: COM10
Serial port: COM3
Parallel port: LPT1
Parallel port: LPT2

If you get a similar output then the package is installed properly.

Not so good news is that Sun no more provides
support for Java communications API for Windows.Why? Here is the answer.
But not to worry..
You can still get the package from
Changes to be then made include in import statements.
So instead of import javax.comm it should now be import*

Check out these links.They helped me.Will help u too.

Posted in JAVA. Tags: . 6 Comments »

Get every new post delivered to your Inbox.

Join 36 other followers