Why do we need out implicit object in JSP When we are supposed to use expressions?
I am studying JSP. I have a d开发者_JS百科oubt. When we use the Expressions in JSP, then why do we need out
implicit object in JSP?
Can anybody explain on this. Thanks
The implicit objects in the JSP context (such as session
, request
and response
) are available in case you need to perform logic in your JSP using these variables. You could see if the user has a particular session variable, or get a parameter from their request or the server's response.
However, it's usually not necessary -- and if you're performing that type of logic in the JSP, it's a sign that your View is doing something that the Controller should have done.
It's just there for convenience and backwards compatiblity. It has been there since the birth of JSP. Nowadays (although, since roughly a decade, when EL was born), you aren't supposed to use it in real world, but scriptlets may be still useful to do quick prototyping/demo/testing.
On the other hand, if it was removed, the compiled JSP servlet would internally not be able to write evaluated EL expressions to the response anymore ;) It is namely been declared (with a variablename as per the JSP spec) inside the compiled JSP servlet class. That's also less or more why it's accessible in the scriptlet scope (which is basically scoped as a method of the compiled JSP servlet class).
精彩评论