Merging query parameters on forward dispatch
- Dominant language
- Java
- Stars
- 325
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
I'm looking for clarification about how (query) parameters are supposed to be handled during a RequestDispatcher and forward scenario. (I can find no prior issues about this)
When checking Servlet Spec 3.1 (Final) Section 9.1.1 It seems to indicate that there should be no merging of query parameters.
And that the old/original URI queryString should be present only as a HttpServletRequest attribute under name `javax.servlet.forward.query_string` (aka `RequestDispatcher.FORWARD_QUERY_STRING`).
```
Original Request URI: /product?id=123
RequestDispatcher Path: /alt/product?id=123
Parameters at forwarded: [id] = [ "123", "123" ]
Equiv query at forwarded: ?id=123&id=123
```
The original request had `?id=123`, the RequestDispatcher was used with `"/alt/product?id=123"` and the request was .forward(), but the parameters at the forwarded destination shows 1 parameter named `"id"` with 2 values `["123", "123"]`.
This shows a behavior where the parameters are merge during the RequestDispatcher + forward.
It might make more sense if you see it like this ...
```
Original Request URI: /product?id=123
RequestDispatcher Path: /alt/product?id=456
Parameters at forwarded: [id] = [ "123", "456" ]
Equiv query at forwarded: ?id=123&id=456
```
The original request had `?id=123`, the RequestDispatcher was used with `"/alt/product?id=456"` (different id value) and the request was .forward(), but the parameters at the forwarded destination shows 1 parameter named `"id"` with 2 values `["123", "456"]`.
This seems odd, why are the parameters merged?
Is this merging actually dictated by the spec?
The TCK does not appear to have any kind of tests for this behavior, so it feels like an undefined behavior between the various Servlet containers.
Here's another scenario ...
```
Original Request URI: /product?id=123
RequestDispatcher Path: /outofbusiness
Parameters at forwarded: [id] = "123"
Equiv query at forwarded: ?id=123
```
The original request had `?id=123`, the RequestDispatcher was used with `"/outofbusiness"` (no id value) and the request was .forward(), but the parameters at the forwarded destination shows 1 parameter named `"id"` with a single value `["123"]`.
Why is this parameter preserved through the forwarded dispatch?
Contributor guide
Research direction
Start with Servlet Spec 3.1 Section 9.1.1 and the RequestDispatcher forward scenarios described here. Compare the expected parameter and query-string behavior with the TCK, which the issue says lacks coverage; done means clarifying the specification or identifying the needed TCK coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100