Saturday, October 22, 2011

Add Mapping to ColdFusion Admin Programmatically

We all know that we can create mapping in ColdFusion server by CF Admin but the question arises here "Can we add a mapping to CF server programmatically". Ans : "YES".

Then How??

<cfscript>

//"/MyMap" is the name of the mapping variable.

mapping = "/MyMap";
serviceFactory = createObject("java","coldfusion.server.ServiceFactory");
mappings = serviceFactory.runtimeService.getMappings();


//Shows all the mapping variables of the server before setting

writeDump(mappings);

//If the mapping variable is not present then create it
if(not(structKeyExists(mappings, mapping)))
{
mappings["/MyMap"] = "Physical directory Path";//e.g-“D:\Project\myPath”
}
//Shows all the mapping variables of the server after setting
writeDump(mappings);

<cfscript>

In above code my mapping variable name is "MyMap". I have created a service factory object to get the mapping structure. Using that structure we can check whether your mapping is present or not and if the mapping is not present you can also create one mapping as shown above.

1 comment:

  1. BlueHost is the best web-hosting provider for any hosting plans you need.

    ReplyDelete

Followers