2011-02-23 7 views
29

JSF의 문제를 해결했습니다. 내 앱 내부 페이지로 리디렉션 할 때 제대로 작동하지만 외부 URL로 리디렉션 할 수 없었습니다. 이걸 안내 해줘?JSF의 외부 URL로 리디렉션

+0

외부 URL로 리디렉션하려고하면 어떻게됩니까? 어떻게 그걸하려고합니까? 몇 가지 코드를 보여주십시오. –

+0

@Matt : 나는 네비게이션 케이스와 결과 값을 만지작 거릴 것이라고 확신합니다. 그건 실제로 가능하지 않습니다. 내부 페이지의 경우 ''또는 'outcome? faces-redirect = true'가 올바르게 작동합니다. – BalusC

답변

71

<a> 또는 <h:outputLink>에 직접 URL을 언급하십시오.

<a href="http://stackoverflow.com">Go to this site!</a> 
<!-- or --> 
<h:outputLink value="http://stackoverflow.com">Go to this site!</h:outputLink> 

또는, <h:commandLink> 다음과 같은 사용하여 콩 조치를 호출해야하는 경우,

<h:form> 
    <h:commandLink value="Go to this site!" action="#{bean.redirect}" /> 
</h:form> 

는 액션 메소드에 ExternalContext#redirect()를 사용합니다. 당신이 IOException는, 서버가 다룰 것이라는 점을 잡을 필요가 없습니다

public void redirect() throws IOException { 
    // ... 

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); 
    externalContext.redirect("http://stackoverflow.com"); 
} 

참고. 또한 URL에 체계 (http:// 또는 https:// 또는 //)를 포함하는 중요성을 유의하십시오. 그렇지 않으면 현재 도메인과 관련하여 해석됩니다.

+0

감사합니다 balus ExternalContext 솔루션 작품, proable 내 URL에 접두사 "http"퍼팅 아니었다, 신속 하 고 특정 대답 다시 +1 – Necronet

관련 문제