2016-05-03 8 views
0

にエラーページをデフォルトに: - 誰かがhttp://localhost:8085/DLMS_Client/PShttp://localhost:8085/PSST/PSSからURLを変更した場合、アプリケーションは、にユーザーをリダイレクトする必要がありますデフォルトのエラーページです。リダイレクトユーザーは、私は、誰かが例のURL</p> <p>を変更するには、特定のエラーページにユーザーをリダイレクトする必要が春

私はここ数日から解決策を探しています。

どのようなヘルプもうまくいくでしょう。

ありがとうございました。

答えて

0

そのためには、春のSimpleExceptionMappingResolverを使用できます。あなたのprojet-servlet.xml

<!-- ExceptionResolverMapping: generate exception specific view --> 

    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 
     <property name="exceptionMappings"> 
      <props> 
       <prop key="com.rail.eseva.exception.UnexpectedException">/unexpectedExceptionView</prop> 
      </props> 
     </property> 
     <property name="defaultErrorView" value="/genericExceptionView"/> 
    </bean> 

でこれを設定する必要があります今、あなたごとにこの例外をスローすることができます

public class UnexpectedException extends RuntimeException { 
    private static final long serialVersionUID = 1L; 


    private String message; 
    private Date date; 
    public UnexpectedException(String message, Date date) { 
     this.date=date; 
     this.message=message; 
    } 
    /** 
    * @return the message 
    */ 
    @Override 
    public String getMessage() { 
     return message; 
    } 
    /** 
    * @return the date 
    */ 
    public Date getDate() { 
     return date; 
    } 

    @Override 
    public String toString() { 
     return message +" "+date.getTime(); 
    } 
} 

と汎用的な例外ビューページ

<body> 

    <h2>Exception occured at: <fmt:formatDate value="${exception.date}" pattern="dd.MM.yyyy"/></h2> 
    <h2>Exception message :</h2> ${exception.message} 

</body> 

like-カスタム例外クラスを作成します要件:

throw new UnexpectedException(e.getMessage(), new Date()); 
+0

こんにちは、お返事ありがとうございます。私の場合、誰かがURLを変更すると、そのデフォルトのエラーページを表示する方法。その場合、コントローラ名は見つかりません。次に、デフォルトのエラーページを表示する必要があります。 – suneel

+0

これが有効なURLでない場合、ページは表示されません(ブラウザ固有の機能)。これが有効なURLであり、処理したくない場合は、コントローラのロジックを処理できます。 –

関連する問題