0

Sorry if it was asked before, I couldn't found.

I have the following link:

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

How can I get value after question mark e.g id=2 from URL?

tuazku
  • 129
  • 1
  • 3
  • 17

1 Answers1

0

I guess that solves:

        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 );
Alfaville
  • 543
  • 7
  • 16