Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect of a requested url contains query string?

Tags:

java

jsp

I want to detect if a requested URL contains query string or not. How can I do so?

like image 948
Mahmoud Saleh Avatar asked Dec 28 '22 07:12

Mahmoud Saleh


2 Answers

You can directly use getQueryString() method

OR

You can check if your url has a query string or not by splitting it on "?" or finding index of the "?" character.

On splitting, your result array must have atleast length greater than 1 and if you take the index route, then the index must be greater than 0 since first character cant be a "?" assuming you will have correct url entered to check for query string.

like image 167
Sachin Shanbhag Avatar answered Jan 14 '23 15:01

Sachin Shanbhag


Something like requestedUrl.indexOf("?") > 0 should do. Because query string parameters are passed by appending ? to the url and then name/value pairs follow.

like image 22
Faisal Feroz Avatar answered Jan 14 '23 14:01

Faisal Feroz