2009-04-07 5 views
5

私はhttp://localhost:8080/getting_started/Hello.actionのような接尾辞に基づいたマッピングの大ファンではないため、フレッド・ダウドのストライプスの本を使い、Hello WorldアプリケーションをフレンドリなURLに変換しようとしています。ここでフレンドリーURLを使用するようにStripesアプリケーションを変換する

は前...

のindex.jspです:

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

のweb.xml:

<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は他の場所で使用されています。 Fred on TheServerSideの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

はとにかく、私は次の変更を行いました、私はアプリをロードしようとするときt 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に2つのフィルタと1つのフィルタマッピングが設定されています:

<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> 
関連する問題