2014-07-24 3 views
0

줄무늬를 사용하여 작은 Java 응용 프로그램을 작성하고 있습니다. 내 ActionBeans에 다시 게시 할 수 있지만 페이지로드시 $(actionBean == null)은 항상 true를 반환합니다. 가능한 문제의 범위를 좁히려면 샘플 Hello World 프로그램을 사용하고 있습니다.ActionBean은 페이지로드시 항상 null입니다.

내하는 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에 중단 점을 설정

, 그들은 페이지로드에 충돌하지 않는, 그래서 어쩌면 바인딩처럼 보인다 발생하지 않습니다. 나는 Apache/Tomcat에 NetBeans의 기본값을 사용하고 있습니다. 이것은 아마도 간단한 해결책 일지 모르지만 공식 문서 외부의 줄무늬에 관한 문서는 비교적 적습니다.

답변

1

빈을 사용하려면 선언해야합니다.

삽입이 :

<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">  
+0

정말 고마워요! 하루를이 문제를 해결하는 데 보냈습니다. 왜 그것이 샘플 코드에 없는지 궁금합니다. –

+0

대단히 반갑습니다. – alfreema

관련 문제