CodeMed CodeMed - 2 years ago 98
Java Question

What int value gets used for ServletRequestAttributes scope?

How does one know what value to give for the

parameter when requesting an attribute value from a

In particular, I would like to get the value of the
attribute of a request sent to the Authorization Endpoint of this GitHub example app. I have a
set up to contain the call to the
ServletRequestAttributes.getAttribute("_csrf", scope)
method, but how do I know what value to enter as the
in order to get the correct

Here is a link to the API.

Also, I found this link to the Spring documentation for bean scopes, but how should one reference one of the scopes in the method call shown above? Simply typing in the String name of a scope results in a compilation error warning in eclipse for trying to pass a String as an int.

Answer Source

The term scope used with ServletRequestAttributes is unrelated to bean scopes.

ServletRequestAttributes defines scope as one of request and session

Accesses objects from servlet request and HTTP session scope, with no distinction between "session" and "global session".

It provides access to request and session attributes through these possible scope values. Constants for these are defined in RequestAttributes, SCOPE_REQUEST and SCOPE_SESSION.

Note that the current implementation of ServletRequestAttributes only ever considers two scenarios. Either you provide SCOPE_REQUEST and it attempts to find a request attribute or you provide any other value (not necessarily SCOPE_SESSION), it ignores it, and attempts to find a session attribute.

Other RequestAttributes implementations may use different scope values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download