2009-04-07 3 views
5

나는 Fred Daoud의 Stripes 책을 통해 작업 중이며 http://localhost:8080/getting_started/Hello.action과 같은 접미사 기반 매핑을 사용하는 팬이 아니기 때문에 Hello World 응용 프로그램을 친숙한 URL로 변환하려고합니다.스트라이프 응용 프로그램에서 친숙한 URL을 사용하도록 변환

<jsp:forward page="/Hello.action"/> 

의 web.xml : 여기

는 전에 ...

의 index.jsp입니다

<servlet-mapping> 
    <servlet-name>DispatcherServlet</servlet-name> 
    <url-pattern>*.action</url-pattern> 
</servlet-mapping> 

그리고 내 HelloActionBean에 아무런 UrlBinding이 없습니다. 나는 책 예를 사용하고있다.

1.5.1을 다운로드하고 내 web.xml에서 StripesFilter 및 StripesDispatcher를 정의 했으므로 책 예제가 이전 버전의 Stripes에 적합한 지 궁금합니다. 반면 DynamicMappingFilter는 다른 곳에서 사용되었습니다. TheServerSide의 Fred가 this article에 있습니다. 그러나

**@UrlBinding("/hello")** 
public class HelloActionBean implements ActionBean 
{ 

:

의 index.jsp :

<jsp:forward page="/hello"/> 

의 web.xml :

<servlet-mapping> 
    <servlet-name>DispatcherServlet</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

HelloActionBean.java

어쨌든, 나는 다음과 같이 변경했다 , 내가 응용 프로그램을로드하려고하면 http://localhost:8080/getting_started hrough 나는이 참조 :

net.sourceforge.stripes.exception.ActionBeanNotFoundException: Could not locate an ActionBean that is bound to the URL [/]. Commons reasons for this include mis-matched URLs and forgetting to implement ActionBean in your class. Registered ActionBeans are: {/hello=class stripesbook.action.HelloActionBean, /controller/DefaultView.action=class net.sourceforge.stripes.controller.DefaultViewActionBean, /hello/=class stripesbook.action.HelloActionBean, /controller/DefaultView.action/=class net.sourceforge.stripes.controller.DefaultViewActionBean} 
    at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.getActionBean(AnnotatedClassActionResolver.java:341) 

을 내가 http://localhost:8080/getting_started/hello를 통해 액세스 할 경우 서버가 다른 후 하나 개의 예외를 던지는 루프에 들어갈 것으로 보인다.

감사의 말 - 감사합니다.

답변

6

내가 몇 가지 다른 일을하려고했는데 그것은 작동있어 ...

나는 web.xml에 기존의 DispatcherServlet 서블릿과 서블릿 매핑 정의를 제거하고 DynamicMappingFilter로 대체.

보너스로 링크 이벤트가 전달되는 방식을 변경하십시오.

http://localhost:8080/getting_started/hello?randomDate= 

http://localhost:8080/getting_started/hello/randomDate 

변화에하는 ActionBean에 UrlBinding된다 : 그것은 단지 DynamicMappingFilter와 디스패처 서블릿을 대체하는 나를 위해 작동하지 않았다

@UrlBinding("/hello/{$event}") 
1

를 (내가 가진 DynamicMappingFilter에 대한 오류 메시지는 StripesFilter와 함께 만 작동합니다. 따라서 이제는 web.xml에 두 개의 필터와 하나의 필터 매핑이 구성되었습니다.

<filter> 
    <display-name>Stripes Filter</display-name> 
    <filter-name>StripesFilter</filter-name> 
    <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> 
    <init-param> 
     <param-name>ActionResolver.Packages</param-name> 
     <param-value>com.package.myactions.package</param-value> 
    </init-param> 
</filter> 

<filter> 
    <description>Dynamically maps URLs to ActionBeans.</description> 
    <display-name>Stripes Dynamic Mapping Filter</display-name> 
    <filter-name>DynamicMappingFilter</filter-name> 
    <filter-class> 
     net.sourceforge.stripes.controller.DynamicMappingFilter 
    </filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>DynamicMappingFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
</filter-mapping>