【问题标题】:Get JSF full url获取 JSF 完整网址
【发布时间】:2013-05-24 11:59:52
【问题描述】:

对不起,如果之前有人问过,我找不到。

我有以下链接:

http://www.mysite.kg/news/news.xhtml?id=2

如何在问号后获取值,例如 URL 中的 id=2?

【问题讨论】:

标签: url jsf-2


【解决方案1】:

我想这解决了:

        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
        String url = req.getRequestURL().toString();
        String id = "";

        Pattern pattern = Pattern.compile( "id=(\\d+)" );
        Matcher matcher = pattern.matcher( url );
        if ( matcher.find() )
            id = matcher.group( 1 );

【讨论】:

    猜你喜欢
    • 2014-08-23
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 2017-11-28
    • 1970-01-01
    相关资源
    最近更新 更多