Java Reference
In-Depth Information
Because EmpBean was defined with a scope of request. Because EnterEmpInfoJSP created a new request, the
EmpBean was not associated with this new request.
There are many ways to solve this problem. We will change the scope of EmpBean from request to session. The
bean scope can be changed very easily because the bean is defined in only one place, the CrtEmpBean class. (If bean
tags had been used, many JSPs would have had to be updated.) The statement that defines the Employee object as an
attribute of the request will be changed to define the Employee object as an attribute of the session . This means that
InsertEmp and DeleteEmp need to be changed to get the bean from the session not the request.
3.
In CrtEmpBean, change the statement that defines the bean to:
pageContext.getSession().setAttribute("EmpBean", emp);
4.
In InsertEmp and DeleteEmp, change the statement that gets the bean to:
emp = (Employee) pageContext.getSession().getAttribute("EmpBean");
Notice that the only change to these statements is that instead of invoking the page context's getRequest method,
the getSession method is used.
5.
Save the files.
6.
In the browser, use the back button to redisplay the EnterEmpInfoJSP (444 should be
specified as the Employee number and Display as the Function).
7.
Click the Submit button.
Again, the Tracy Tester information and a Delete button should be displayed. This time, however, CrtEmpBean
created EmpBean as a session bean.
8.
Click the Delete button.
The Tracy Tester name should be displayed with the text and a Confirm button as in Figure 11-18 .
Figure 11-18.
Search WWH ::




Custom Search