FibonnaciAccessBean.java.

Enterprise Java
Tag Libraries: JSPs in the Enterprise
by Dion Almaer
Listing 4. FibonnaciAccessBean.java.


package com.customware.fib;

import javax.servlet.http.HttpServletRequest;

public class FibonnaciAccessBean extends Fibonnaci {

   // Method to calculate the fibonacci sequence
   public String calculateFibonacci( HttpServletRequest request ) {
      int num = 0;

      // Parse an int out of the string
      String input = request.getParameter("num");
      if (input == null) return "Need to pass parameter 'num'";

      try {
           num = Integer.parseInt( input.trim() );
      } catch (NumberFormatException e) {
               return "Need to pass number parameter 'num'";
      }

      int result = super.calculateFibonacci( num );

      return "Fibonnaci[ " + num + " ]: " + result;
   }

}

About the Author

Dion Almaer is a senior consultant for CustomWare in Boulder, CO. He can be reached at dion@customware.com.

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.