0

My servlet needs to receive 2 parameters to respond.

My favorite solution (but it doesn't work in my context):

http://domain.com/?param1=something&param2=anything

because: I've another application which requires that a url ends with "/". But I can't create a servlet which accepts urls like "http://domain.com/?param1=something&param2=anything/" <<- / at the end.

My second solution is: http://domain.com/param1/param2/ I could split the requested url by "/" and I would have my 2 parameters. But it's not that nice..

Is there a better way to pass through 2 parameters and have an url which ends on a "/"?

wassermine
  • 131
  • 1
  • 1
  • 9

2 Answers2

1

I think it is not possible. As it is defined in the HTTP RFC "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]] After the first "?" there is the query part. So in your example http://domain.com/?param1=something&param2=anything/ That means param2 value is anything/ (with the slash in the end)

Of course you can bind your servlet to /* url-pattern and process the parameters in the servlet using ServletRequest.getParameter(). But don't forget that your param2 will end with a /

András Tóth
  • 605
  • 4
  • 12
1

According to RFC 3986, section 3.3, it is possible to assign a set of parameters to each path segment like so:

http://domain.com/path;param1=value1;param2=value2/subpath/subsubpath/

So you can have parameters without the query part.

But the downside is:

  • What you want to achieve is mabye not the intended use case for that feature.
  • Other than for query parameters, there is no API support for segment parameters. So you have to parse the parameters on your own.
Community
  • 1
  • 1
vanje
  • 10,180
  • 2
  • 31
  • 47