Codice completo

Listato 2. Applicazione per utilizzare DynaActionForm

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;

public class DynamicLookupAction
  extends Action {

  public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

    Double price = null;

    String target = new String("success");

    if (form != null) {
      DynaActionForm lookupForm = (DynaActionForm) form;
    
      String symbol = (String) lookupForm.get("symbol");

      price = new Double(12.34);
    }

    if (price == null) {
      target = new String("failure");
    } else {
      request.setAttribute("PRICE", price);
    }

    return mapping.findForward(target);
  }
}