Java Reference
In-Depth Information
L ISTING 13.1
Continued
throws ServletException, IOException {
// Get the name of the Transaction to perform
String serviceName = request.getParameter(“service”);
if (serviceName == null) {
throw new ServletException(“No service named!”);
}
// Get the target of the request
String target = request.getParameter(“target”);
if (target == null) {
throw new ServletException(“No target named!”);
}
ServletContext context = getServletContext();
// Create and execute an instance of the named service
try {
// Create an instance of the fully qualified Service Class
Class cls = Class.forName(serviceName);
Service service = (Service)cls.newInstance();
// Execute the Transaction
service.execute(request, response, context);
}
catch (ClassNotFoundException ce) {
throw new ServletException(ce.getMessage());
}
catch (IllegalAccessException iae) {
throw new ServletException(iae.getMessage());
}
catch (Exception e) {
throw new ServletException(e.getMessage());
}
// Forward the results
forward(request, response, target);
}
}
We need to discuss two sections of the Controller class. The first is the heart of the class,
which is contained in the following code snippet:
// Create and execute an instance of the named service
try {
// Create an instance of the fully qualified Service Class
Class cls = Class.forName(serviceName);
Search WWH ::




Custom Search