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?
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?
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 );