About Struts
in struts,I am Making Action class like this code...
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LookupAction extends Action
{
protected Double getQuote(String symbol)
{
if ( symbol.equalsIgnoreCase("Narendra") )
{
return new Double(25.00);
}
return null;
}
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
Double price = null;
// Default target to success
String target = new String("success");
if ( form != null )
{
// Use the LookupForm to get the request parameters
LookupForm lookupForm = (LookupForm)form;
String symbol = lookupForm.getSymbol();
price = getQuote(symbol);
}
// Set the target to failure
if ( price == null )
{
target = new String("failure");
}
else
{
request.setAttribute("PRICE", price);
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}
But it is not working.but if i will use this code then it is working------
import java.io.IOException;
import java.io.PrintStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
public class LookupAction extends Action
{
public LookupAction()
{
}
protected Double getQuote(String s)
{
if(s.equalsIgnoreCase("Narendra"))
return new Double(25D);
else
return null;
}
public ActionForward perform(ActionMapping actionmapping, ActionForm actionform, HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws IOException, ServletException
{
Object obj = null;
System.out.println("perform");
if(actionform != null)
{
LookupForm lookupform = (LookupForm)actionform;
String s = lookupform.getSymbol();
Double double1 = getQuote(s);
}
return actionmapping.findForward("success");
}
}
means when ever i am passing object like target itcis not working
but when evr i m passing "success" it is working.
why?????????
i am waiting 4 reply.
Regards,
Nandu
|