How to get Bean data in JSP

I have a bean defined as PersonBeanin a session area.

I want to find PersonBean.personIdon the jsp page.

I want this on the jsp page because I want to do some calculations based on this personId. Anyone have an idea how to get the same.

In JSP I can print the same using jsf

<h:outputText value="#{PersonBean.personId}" />

However, I need this value to be assigned to some integer value in jsp, as shown below.

<h:outputText value="#{PersonBean.personId}" />
<%
   int i = new PersonBean().getPersonId;
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%>

I thought it int i = new PersonBean().getPersonId;would work, however it does not work. Any idea how I get this?

Update 1

I also tried

<jsp:useBean id="sessionPersonalDataBean" class="com.sac.databean.PersonalInformationDataBean" scope="session"/>
<%
   out.print("my id is " + sessionPersonalDataBean.getPersonId());
%>

However, I get the output as my id is 0instead my id is 0.

Note:

When I use <h:outputText value=#{PersonalInformationDataBean.personId} />, I get the correct output.

0
1

JSP, : JSP - . bean "PersonBean", :

PersonBean p = (PersonBean) request.getSession().getAttribute("PersonBean");

"PersonalInformationDataBean", , ,

PersonBean p = (PersonBean) request.getSession().getAttribute("PersonalInformationDataBean");

new PersonBean() PersonBean, , , , , . Java-, Java OO JSF.

+1

All Articles