configure servlet with coldfusion

Major difference from ColdFusion 9 to ColdFusion 10 is the underlying architecture. ColdFusion 9 uses JRun as the underlying architecture, whereas ColdFusion 10 and higher version use Tomcat.

Due to this, the way servlets used to configure has changed slightly. Configuring servlet with ColdFusion 10 and later versions is no more a challenge. Here is a sample servlet to test the functionality. Here are the steps to implement:-

  1. Place the Servlet.cfm in your webroot of your application.
  2. Place the NewServlet.class file at \ColdFusion10\cfusion\wwwroot\WEB-INF\classes\. If the class file doesn’t work, then compile the NewServlet.java with java 7 and place the compiled class file at the mentioned location.
  3. Add the following in \ColdFusion10\cfusion\wwwroot\WEB-INF\web.xml and save the file.

<servlet>

<description></description>

<display-name>NewServlet</display-name>

<servlet-name>NewServlet</servlet-name>

<servlet-class>NewServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>NewServlet</servlet-name>

<url-pattern>/NewServlet</url-pattern>

</servlet-mapping>

4.  Restart the “ColdFusion 10 Application Service” and browse to http://ip:port/NewServlet.cfm (This is not the internal port, but your website port). Default port is 80.

If the web page appears as mentioned below, then it confirms the Servlet functionality. Now you are good to go ahead and test your servlets.

servlet success

The same steps are applicable for ColdFusion 11 as well.

Note: – If you get Error 500 after applying the steps, then the problem is with your ColdFusion JRE version. Compile the NewServlet.java with the Java version, same as of your ColdFusion or higher.

Advertisements

3 thoughts on “configure servlet with coldfusion

  1. I know this is an old blog posting but it is pretty much exactly what I am trying to do and wondering are there any additional steps for CF11?

    I have a working application on ColdFusion 9 that uses some custom Java class files. I am trying to get the application to work in ColdFusion 11. I can do a CreateObject() successfully to those class files on the CF11 server so guessing they are compatible with differences in Java versions. When I try doing a servlet-mapping so they can be called via a URL like you show, I just get a 404 error in the web browser. It seems like the mapping is not going to effect but was not sure if perhaps any log files I can look at to see if some error is actually happening?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s