Codice completo

Listato 2. Azione per utilizzare l'estensione

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

public class LookupAction2 extends Action {

    public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    
        ProvaActionMapping provaMapping = (ProvaActionMapping) mapping;
        
        Double price = null;
        String symbol = null;
        
        String target = new String("success");
        
        if (form!=null) {
            LookupForm2 lookupForm = (LookupForm2) form;
            
            symbol = lookupForm.getSymbol();
            price = new Double(1234.56);
        }
        
        if (price==null) {
            target = new String("failure");
        } else {
            if (provaMapping.getLogResults()) {
                System.err.println("SYMBOL: " + symbol + " PRICE: " + price);
            }
            request.setAttribute("PRICE", price);
        }
        
        return mapping.findForward(target);
    
    }
}