It's available as an attribute of the page, request, session or application scope. If the scope is known, just call getAttribute()
on the scope of interest.
<%
Object pageAttribute = pageContext.getAttribute("name");
Object requestAttribute = request.getAttribute("name");
Object sessionAttribute = session.getAttribute("name");
Object applicationAttribute = application.getAttribute("name");
%>
Or if the scope is unknown, use PageContext#findAttribute()
. It searches in subsequently the page, request, session and application scopes and returns the first match.
<%
Object unknownScopedAttribute = pageContext.findAttribute("name");
%>
The above is also basically what EL is doing under the covers.
Unrelated to the concrete problem, this is definitely a workaround. If you elaborate in detail why need to do this, then we may be able to come up with real solutions instead of workarounds. In the meanwhile, read this thoroughly: How to avoid Java code in JSP files?