I am working on JSP and servlets. I need to fetch values from java bean and assign it some other variable over JSP.
Usually I fetch the value in html tags as ${abcd.variable_name}
but this thing can't be used it we want to get some value in <% %>
I am working on JSP and servlets. I need to fetch values from java bean and assign it some other variable over JSP.
Usually I fetch the value in html tags as ${abcd.variable_name}
but this thing can't be used it we want to get some value in <% %>
That depends on where the bean is stored. If it is stored in the request scope as a request attribute, just get it back as request attribute:
<%
Bean bean = (Bean) request.getAttribute("bean");
// ...
%>
Or if it's stored in the session scope as a session attribute, just get it back as session attribute:
<%
Bean bean = (Bean) session.getAttribute("bean");
// ...
%>
Or if it's stored in the application scope as an application attribute, just get it back as application attribute:
<%
Bean bean = (Bean) application.getAttribute("bean");
// ...
%>
However, you're doing the desired job at the wrong place. It has to be done in a normal Java class like a servlet or at least the action class of the MVC framework you're using, if any.