I can't see anything wrong with your code. If you
want, you can download the source code from the book's
website at www.wiley.com/compbooks/goodwill 

rc
--- Rama <[EMAIL PROTECTED]> wrote:
> Hi,
> I have been trying to implement Struts for a simple
> applicaiton.
> I am using WLS 6.1 and Struts 1.02. 
> 
> 
> Application: User enters a stock symbol and clicks
> submit button in the index page.
> if the value is "SUNW" , it is success and value is
> displayed,
> else it is failure , user is forwarded to starting
> index page.
> 
> Here is the following code
> 
> 
> index.jsp
> ....
> <%@ page language ="java" %>
> <%@ taglib uri="/WEB-inf/struts-html.tld"
> prefix="html" %>
> ....
> <html:form action="Lookup" name="lookupForm"
> type="LookupForm" >
> Symbol : <html:text property="symbol" />
> <html:submit />  
> </html:form>
> .....
> 
> 
> 
> 
> LookupAction.java
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.apache.struts.action.*;
> 
> public class  LookupAction extends Action
> {
>       protected Double getQuote(String symbol)
>       {
>               if (symbol.equalsIgnoreCase("SUNW") )
>               {
>                       return new Double(25.00);
> 
>               }
>               return null;
>       }
> 
>       public ActionForward execute(ActionMapping mapping,
>               ActionForm form,
>               HttpServletRequest request,
>               HttpServletResponse response) throws
> ServletException,IOException
>       {
>               Double price = null;
>               // set default target to success
> 
>               String target = new String("success");
> 
>               if (form != null)
>               {
>                       // use the LookupFoprm to get 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) );
> 
>       }
> }
> 
> 
> 
> LookupForm.java
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionMapping;
> 
> public class  LookupForm extends ActionForm
> {
>       private String symbol = null;
> 
>       public String getSymbol()
>       { 
>               return (symbol);
>       }
>       public void setSymbol(String symbol)
>       {
>               this.symbol = symbol;
>       }
> 
>       public void reset(ActionMapping mapping,
> HttpServletRequest request)
>       {
>               this.symbol=null;
>       }
> 
> }
> 
> 
> 
> 
>  struts-config.xml
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <!DOCTYPE struts-config PUBLIC "-//Apache Software
> Foundation//DTD Struts Configuration 1.0//EN"
>
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd";>
> <struts-config>
>       
>       <form-beans>
>               <form-bean name="lookupForm" type="LookupForm" />
>       </form-beans>
>       <action-mappings>
>               <action path="/Lookup" type= "LookupAction"
> name="lookupForm" input="/index.jsp">
>                       <forward name="success" path="/quote.jsp" />
>                       <forward name="failure" path="/index.jsp" />
>               </action>       
>       </action-mappings>
> </struts-config>
> 
> 
> 
> 
> This is the excerpt from web.xml
>   <taglib>
>       <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
> 
>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
>   </taglib>
> 
>  <servlet>
>       <servlet-name>action</servlet-name>
> 
>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
>       <init-param>
>               <param-name>config</param-name>
>       
>
<param-value>/WEB-INF/struts-config.xml</param-value>
>       </init-param>
>       <load-on-startup>1</load-on-startup>
> </servlet>
> 
> <servlet-mapping>
>       <servlet-name>action</servlet-name>
>       <url-pattern>*.do</url-pattern>
> </servlet-mapping>
>  quote.jsp
> .....
> 
>                       Current Price : <%= request.getAttribute("PRICE")
> %>
>               
> .......
> 
> 
> When I entered the SUNW in the text box, I am
> forwarded to a blank page. 
> I am not seeing any results... why??? 
> 
> Please anyone let me know what I am missing?
> Any ideas are really appreciated
> Thanks in Advance
> Rama
> 
> 
> 



__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to