A website I'm making has been growing larger and larger feature wise. Which means there's more URL parameters that get passed from page A to B or B to C, etc.

Does anyone have any tips for how to keep track of and use parameter keys and expected values?

Ex. Say a url I need to build is www.example.com?type=this&mode=a

Is there some kind of a system that will let me easily keep track of the fact that the "type" parameter key is in fact "type"?

I tried to keep them all in a constants class, but that class quickly grew out of hand.

public class URLParameters { 

  public static final String TYPE = "type" ; 
  public static final String MODE = "mode" ; 

  //more "keys"

  public static class Values { 

    public static final String TYPE_THIS = "this" ; 
    public static final String TYPE_THAT = "that" ; 

    public static final String MODE_PRIMARY = "a" ; 
    public static final String MODE_SECONDARY = "b" ;

    //more expected values


I've always used globally accessible objects that are responsible for managing all variables in and out. This prevents duplication of code by having a singular method such CreateQueryString() and properties on the object that are instructed to look for specific keys. This allows you to put in extra data scrubbing if you need, etc. It also allows you to discard invalid keys that might have unintended consequences if the structure you're using is vulnerable to it.

I always try to keep my query strings short, but I recall a job I did in FuseBox a ways back that we had to employ this method. When you get right down to it, that's basically what FuseBox is. It's an object structure that uses structured query strings to control the presentation of the site. Our implementation, however, was geared towards specific global functionality.

The drawback to this method is that it then becomes a requirement that any page which expects to use a query string variable will have to register that variable as a property in the global object. While this will help prevent the duplication or reusage of specific keys, it will still be a little tedious and possibly even cumbersome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.