程序文件
package wiley;
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("SUNW") ) {
System.out.print("sunw");
return new Double(25.00);
}
return null;
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
System.out.println("in action execute");
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);
}
System.out.println(target);
// Forward to the appropriate View
return (mapping.findForward(target));
}
}

解决方案 »

  1.   

    index.jsp:<%@ page language="java" %>
    <%@ taglib  uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <html>
    <body>
    <html:form action="Lookup"
    name="lookupForm"
    type="wiley.LookupForm" >
    <table width="45%" border="0">
    <tr>
    <td>Symbol:</td>
    <td><html:text property="symbol" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><html:submit /></td>
    </tr>
    </table>
    </html:form>
    </body>
    </html>
      

  2.   

    quote.jsp
    <html>
    <body>
    Current Price : <%= request.getAttribute("PRICE") %>
    </body>
    </html>
      

  3.   

    不明白你说的
    “不能forward”
    是指什么呢。你的原帖也看了一下。
    上面的朋友都已经提了很多很好的折中处理方式啊。
      

  4.   

    forward指这里:
    return (mapping.findForward(target));
    在index.jsp中输入:SUNW,提交后不能转向quote.jsp页面
      

  5.   

    如果转向"/index.jsp”说明 price == null ,
    如果price == null说明getQuote(symbol);或者form != null
    你多用一些System.out.println("");来调试;
    或者再多加一些<forward name="success" path="/quote.jsp" redirect="true"/>
    <forward name="failure" path="/index.jsp" redirect="true"/>
    <forward ........>
    在不用的地方放不同的forward ,看它forward 到哪一页,
    这样之后,你一定能找出问题所在。
      

  6.   

    你的form就不就写错了?
    这样写应该没有问题,我就这样写的如下
    <html:form action="/Lookup.do">
    ....
    </html:form>
    而你的就这样的
    <html:form action="Lookup" name="lookupForm" type="wiley.LookupForm" >
    ...
    </html:form>
    你比较一下吧.
      

  7.   

    to: kui(kui) 
    action类里面的System.out.println(xxx)根本就不执行
      

  8.   

    zdhsoft(冬瓜猫):
    改过来也不行
      

  9.   

    下面是我做的,我用jbuilderx向导生成的,没有问题
    jsp文件部门:
    <html:form action="/testAction.do" method="post">
    <br><br>
    <html:text property="test"></html:text>
    <html:submit value="submit" property="submit"/>
    <html:reset value="reset"/>
    </html:form>struct-config.xml部分
      <form-beans>
        <form-bean name="testForm" type="test1.testForm" />
      </form-beans>
      <action-mappings>
        <action input="/index.jsp" name="testForm" path="/testAction" scope="request" type="test1.testAction" validate="true">
          <forward name="test2" path="/test2.jsp" />
        </action>
      </action-mappings>类testAction
    package test1;import org.apache.struts.action.*;
    import javax.servlet.http.*;public class testAction extends Action {
      public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        testForm testForm = (testForm) actionForm;
        return actionMapping.findForward("test2");
      }
    }FormBean:
    package test1;import org.apache.struts.action.*;
    import javax.servlet.http.*;public class testForm extends ActionForm {
      private String test;
      public String getTest() {
        return test;
      }
      public void setTest(String test) {
        this.test = test;
      }
      public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
        test = null;
      }
    }这个例子是获通过的,你再试试,struts刚开孡搞是有很多问题的
      

  10.   

    <forward name="failure" path="/index.jsp" redirect="true"/>
    把你的path路径写为全路径,即:假如你的测试是这样:
    http://localhost:7001/xxx/index.jsp
    则这样写
    <forward name="failure" path="/xxx/index.jsp" redirect="true"/>
    试试
      

  11.   

    下面是我的tomcat启动信息:
    Starting service Tomcat-Apache
    Apache Tomcat/4.0.4
    New org.apache.struts.webapp.example.User
    Set org.apache.struts.webapp.example.User properties
    New org.apache.struts.webapp.example.Subscription
    Set org.apache.struts.webapp.example.Subscription properties
    Call org.apache.struts.webapp.example.Subscription.setUser(User[username=user, f
    ullName=John Q. User])
    Pop org.apache.struts.webapp.example.Subscription
    New org.apache.struts.webapp.example.Subscription
    Set org.apache.struts.webapp.example.Subscription properties
    Call org.apache.struts.webapp.example.Subscription.setUser(User[username=user, f
    ullName=John Q. User])
    Pop org.apache.struts.webapp.example.Subscription
    Call org.apache.struts.webapp.example.DatabaseServlet.addUser(User[username=user
    , fullName=John Q. User])
    Pop org.apache.struts.webapp.example.User
    register('-//Apache Software Foundation//DTD Struts Configuration 1.0//EN', 'jar
    :file:D:/Tomcat/webapps/struts-example/WEB-INF/lib/struts.jar!/org/apache/struts
    /resources/struts-config_1_0.dtd'
    register('-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN', 'jar:file:D:/
    Tomcat/webapps/struts-example/WEB-INF/lib/struts.jar!/org/apache/struts/resource
    s/web-app_2_2.dtd'
    register('-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN', 'jar:file:D:/
    Tomcat/webapps/struts-example/WEB-INF/lib/struts.jar!/org/apache/struts/resource
    s/web-app_2_3.dtd'
    resolveEntity('-//Apache Software Foundation//DTD Struts Configuration 1.0//EN',
     'http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd')
     Resolving to alternate DTD 'jar:file:D:/Tomcat/webapps/struts-example/WEB-INF/l
    ib/struts.jar!/org/apache/struts/resources/struts-config_1_0.dtd'
    New org.apache.struts.action.ActionFormBean
    Set org.apache.struts.action.ActionFormBean properties
    Call org.apache.struts.action.ActionServlet.addFormBean(ActionFormBean[lookupFor
    m])
    Pop org.apache.struts.action.ActionFormBean
    New org.apache.struts.action.ActionFormBean
    Set org.apache.struts.action.ActionFormBean properties
    Call org.apache.struts.action.ActionServlet.addFormBean(ActionFormBean[logonForm
    ])
    Pop org.apache.struts.action.ActionFormBean
    New org.apache.struts.action.ActionFormBean
    Set org.apache.struts.action.ActionFormBean properties
    Call org.apache.struts.action.ActionServlet.addFormBean(ActionFormBean[registrat
    ionForm])
    Pop org.apache.struts.action.ActionFormBean
    New org.apache.struts.action.ActionFormBean
    Set org.apache.struts.action.ActionFormBean properties
    Call org.apache.struts.action.ActionServlet.addFormBean(ActionFormBean[subscript
    ionForm])
    Pop org.apache.struts.action.ActionFormBean
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionServlet.addForward(ActionForward[logoff])
    Pop org.apache.struts.action.ActionForward
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionServlet.addForward(ActionForward[logon])
    Pop org.apache.struts.action.ActionForward
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionServlet.addForward(ActionForward[success])
    Pop org.apache.struts.action.ActionForward
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionServlet.addForward(ActionForward[success])
    Pop org.apache.struts.action.ActionForward
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionMapping.addForward(ActionForward[success])
    Pop org.apache.struts.action.ActionForward
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/editR
    egistration, type=org.apache.struts.webapp.example.EditRegistrationAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionMapping.addForward(ActionForward[failure])
    Pop org.apache.struts.action.ActionForward
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionMapping.addForward(ActionForward[success])
    Pop org.apache.struts.action.ActionForward
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/editS
    ubscription, type=org.apache.struts.webapp.example.EditSubscriptionAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    New org.apache.struts.action.ActionForward
      

  12.   


    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionMapping.addForward(ActionForward[success])
    Pop org.apache.struts.action.ActionForward
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/logof
    f, type=org.apache.struts.webapp.example.LogoffAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/logon
    , type=org.apache.struts.webapp.example.LogonAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/saveR
    egistration, type=org.apache.struts.webapp.example.SaveRegistrationAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionMapping.addForward(ActionForward[success])
    Pop org.apache.struts.action.ActionForward
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/saveS
    ubscription, type=org.apache.struts.webapp.example.SaveSubscriptionAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/tour]
    )
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/admin
    /addFormBean, type=org.apache.struts.actions.AddFormBeanAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/admin
    /addForward, type=org.apache.struts.actions.AddForwardAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/admin
    /addMapping, type=org.apache.struts.actions.AddMappingAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/admin
    /reload, type=org.apache.struts.actions.ReloadAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/admin
    /removeFormBean, type=org.apache.struts.actions.RemoveFormBeanAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/admin
    /removeForward, type=org.apache.struts.actions.RemoveForwardAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/admin
    /removeMapping, type=org.apache.struts.actions.RemoveMappingAction])
    Pop org.apache.struts.action.ActionMapping
    New org.apache.struts.action.ActionMapping
    Set org.apache.struts.action.ActionMapping properties
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionMapping.addForward(ActionForward[success])
    Pop org.apache.struts.action.ActionForward
    New org.apache.struts.action.ActionForward
    Set org.apache.struts.action.ActionForward properties
    Call org.apache.struts.action.ActionMapping.addForward(ActionForward[failure])
    Pop org.apache.struts.action.ActionForward
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/Looku
    p, type=wiley.LookupAction])
    Pop org.apache.struts.action.ActionMapping
    register('-//Apache Software Foundation//DTD Struts Configuration 1.0//EN', 'jar
    :file:D:/Tomcat/webapps/struts-example/WEB-INF/lib/struts.jar!/org/apache/struts
    /resources/struts-config_1_0.dtd'
    register('-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN', 'jar:file:D:/
    Tomcat/webapps/struts-example/WEB-INF/lib/struts.jar!/org/apache/struts/resource
    s/web-app_2_2.dtd'
    register('-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN', 'jar:file:D:/
    Tomcat/webapps/struts-example/WEB-INF/lib/struts.jar!/org/apache/struts/resource
    s/web-app_2_3.dtd'
    resolveEntity('-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN', 'http://
    java.sun.com/j2ee/dtds/web-app_2_2.dtd')
     Resolving to alternate DTD 'jar:file:D:/Tomcat/webapps/struts-example/WEB-INF/l
    ib/struts.jar!/org/apache/struts/resources/web-app_2_2.dtd'
    Call org.apache.struts.action.ActionServlet.addServletMapping(action/java.lang.S
    tring,*.do/java.lang.String)
    Starting service Tomcat-Apache
    Apache Tomcat/4.0.4
      

  13.   

    奇怪我把struts-config.xml中的action改成:<action path="/Lookup"
    type="wiley.test.LookupAction"          //改了这里
    name="lookupForm"
    input="/index.jsp">
    <forward name="success" path="/struts/quote.jsp" redirect="true"/>
    <forward name="failure" path="/struts/index.jsp" redirect="true"/>
    </action>可是重新启动tomcat还是显示
    Call org.apache.struts.action.ActionServlet.addMapping(ActionMapping[path=/Looku
    p, type=wiley.LookupAction])
    Pop org.apache.struts.action.ActionMapping这是什么原因?
      

  14.   

    楼主你的 form 配置是不是正确呢???
    <action path="/Lookup"
    type="wiley.test.LookupAction"          //改了这里
    name="lookupForm"
    scope="request"
    input="/index.jsp">
    <forward name="success" path="/struts/quote.jsp" redirect="true"/>
    <forward name="failure" path="/struts/index.jsp" redirect="true"/>
    </action>这样在试一下看看可以不?
      

  15.   

    to: xinshou1979330(Success.java)
    form没有问题,可以很好的工作
    另外,我已经像你说的那样试过了,也不行.我像这样就可以forwardstruts-config.xml:<action    path="/tt"
                forward="/tt.htm">
        </action>tt.jsp
    <%@ page language="java" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><html:link page="/tt.do">
    tt.do
    </html:link>
    可以成功的forward到tt.htm页面