2016-10-21 14 views
0

次のように残りのconfigクラスを作成したPOM空の残りのパスの設定、カントアクセスアプリページ

<dependency> 
    <groupId>org.jboss.resteasy</groupId> 
    <artifactId>resteasy-jaxrs</artifactId> 
    <version>2.2.1.GA</version> 
</dependency> 

<dependency> 
    <groupId>org.jboss.resteasy</groupId> 
    <artifactId>resteasy-jackson-provider</artifactId> 
    <version>2.2.1.GA</version> 
</dependency> 

<dependency> 
    <groupId>org.jboss.resteasy</groupId> 
    <artifactId>resteasy-jaxb-provider</artifactId> 
    <version>2.2.0.GA</version> 
</dependency> 

を追加しました依存関係を次のように私は、私のJavaアプリケーションでAPIサービスを作成するためのRESTEasyを設定し

@ApplicationPath("/") 
public class RestClass extends Application { 
    private Set<Object> singletons = new HashSet<Object>(); 

    public RestClass() { 
     singletons.add(new Stimulant()); 
    } 

    @Override 
    public Set<Object> getSingletons() { 
     return singletons; 
    } 
} 

これは、

JSONデータを提供し、私のサービスクラスであります

私は、URLを叩きながら、私は私のアプリのホーム・ページにアクセスしていた場合localhost:8080/myApp/{whatever}

問題があり、それはページ(localhost:8080/myApp)を示していないJSONデータを取得することができています。アプリのホームページを開くのではなく、apiの呼び出しに行きました。

この問題はどのようにして発生しますか?

答えて

0

フィルタサーブレットでこれを行う必要があります。

あなたの残りの設定を "/ f"としましょう。ブラウザでURLを入力すると/fを削除し、必要な場所に "/ f"を追加してリクエストを転送することができます。

単純なコード、

public void doFilter(ServletRequest request, ServletResponse response, 
     FilterChain chain) throws IOException, ServletException { 
     if (request instanceof HttpServletRequest) { 
     String path = ((HttpServletRequest) request).getServletPath(); 
     String newPath = null; 

       newPath = "f" + path; 
      } 

     } else { 
      newPath = path; 
     } 
     request.getRequestDispatcher(newPath).forward(request, response); 
     return; 
    } 
    chain.doFilter(request, response); 
} 
関連する問題