 |
Return to article.
Listing 3
public class RSExample extends RemoteScriptingServlet {
public static String getSubcategories (String catstr) throws Exception
{
// sure, there is a possibility of an exception happening here, but
// RemoteScriptingServlet will catch it and deal with it appropriately
int catid = Integer.parseInt(catstr);
String subcats[][] = new String[][] {
new String[] {"Category 0 - Subcategory 0", "Category 0 - Subcategory 1", "Category 0 - Subcategory 2"},
new String[] {"Category 1 - Subcategory 0", "Category 1 - Subcategory 1", "Category 1 - Subcategory 2"},
new String[] {"Category 2 - Subcategory 0", "Category 2 - Subcategory 1", "Category 2 - Subcategory 2"},
};
String retval = "";
for (int i = 0; i < subcats[catid].length; i++) {
// build a string with "index,value" pairs separated by semicolons
// for demo brevity, we'll assume that no commas or semicolons are present
// in the values of subcats[catid][i]
retval += i + "," + subcats[catid][i] + ";";
}
return retval;
}
}
|
Return to article.
|  |
|