0

I have been trying to obtain the id parameter:

http://localhost/client/edit.xhtml?id=0001

I already tried to obtain the parameter with HttpServletRequest using the next code block, but I obtain > id = 1

HttpServletRequest req = (HttpServletRequest) externalContext.getRequest();
String urlParams = req.getQueryString();

How can I obtain > id = 0001?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 2
    Well, how about `req.getParameter("id")`? Or since you added the JSF tag, make use of JSF's facilities. – Thomas Nov 11 '20 at 15:19
  • Btw, using `getQueryString()` should return `"id=0001"`- it would not change the query string. If you get a string other than the one you've appended to your url you probably have some url rewriting sitting in between. – Thomas Nov 11 '20 at 15:22
  • JSF way would be [How do I process GET query string URL parameters in backing bean on page load?](https://stackoverflow.com/questions/10724428/), or is your code part of a servlet class? – f_puras Nov 11 '20 at 15:26
  • @Thomas you are right. There was a rewriting. Now with urlParams = req.getQueryString() I get 0001. Thanks – Marc Jordana Vilà Nov 12 '20 at 06:51
  • Does this answer your question? [How do I process GET query string URL parameters in backing bean on page load?](https://stackoverflow.com/questions/10724428/how-do-i-process-get-query-string-url-parameters-in-backing-bean-on-page-load) – Vsevolod Golovanov Nov 12 '20 at 14:23

1 Answers1

1

To get id you can do this

req.getParameter("id");