Java ActionBean在页面加载时始终为空

Java ActionBean在页面加载时始终为空,java,stripes,Java,Stripes,我正在使用Stripes构建一个小型Java应用程序。我可以发回我的ActionBeans,但是在页面加载时,$(actionBean==null)总是返回true。为了缩小可能出现的问题,我使用了一个示例Hello World程序 我的ActionBean: package stripesbook.action; import java.util.Date; import java.util.Random; import net.sourceforge.stripes.action.Acti

我正在使用Stripes构建一个小型Java应用程序。我可以发回我的ActionBeans,但是在页面加载时,
$(actionBean==null)
总是返回true。为了缩小可能出现的问题,我使用了一个示例Hello World程序

我的ActionBean:

package stripesbook.action;

import java.util.Date;
import java.util.Random;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

public class HelloActionBean implements ActionBean {/* (1) */
    private ActionBeanContext ctx;
    public ActionBeanContext getContext() { return ctx; }
    public void setContext(ActionBeanContext ctx) { this.ctx = ctx; }

    private Date date;/* (2) */
    public Date getDate() {
        return date;
    }
    @DefaultHandler
    public Resolution currentDate() {/* (3) */
        date = new Date();
        return new ForwardResolution(VIEW);
    }
    public Resolution randomDate() {
        long max = System.currentTimeMillis();
        long random = new Random().nextLong() % max;
        date = new Date(random);
        return new ForwardResolution(VIEW);
    }
    private static final String VIEW = "/hello.jsp";
}
和我的jsp页面:

<%@page contentType="text/html;charset=ISO-8859-1" language="java"%>
<%@taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Hello, Stripes!</title>
  </head>
  <body>
    <h3>Hello, Stripes!</h3>
    <p>
      Date and time:
      <br>
      <b>
        <p>${actionBean == null}</p>
        <fmt:formatDate type="both" dateStyle="full"
          value="${actionBean.date}"/>
      </b>
    </p>
    <p>
      <s:link beanclass="stripesbook.action.HelloActionBean"
        event="currentDate">
        Show the current date and time
      </s:link> |
      <s:link beanclass="stripesbook.action.HelloActionBean"
        event="randomDate">
        Show a random date and time
      </s:link>
    </p>
  </body>
</html>

你好,条纹!
你好,条纹!

日期和时间:

${actionBean==null}

显示当前日期和时间 | 显示随机的日期和时间


当我在ActionBean中设置断点时,它们在页面加载时不会被命中,所以看起来可能绑定没有发生。我正在为Apache/Tomcat使用NetBeans的默认值。这可能是一个简单的解决方案,但官方文档之外的条纹文档相对较少。

要使用bean,您需要声明它

插入以下内容:

 <jsp:useBean id="actionBean" class="stripesbook.action.HelloActionBean"/>

在JSP的顶部,如下所示:

<%@page contentType="text/html;charset=ISO-8859-1" language="java"%>
<%@taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<jsp:useBean id="actionBean" class="stripesbook.action.HelloActionBean"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">    

非常感谢!花了一天的时间想弄明白。想知道为什么它不在示例代码中。