Java Reference
In-Depth Information
More JSP Tags
We are going to change our Controller from a servlet to a JSP, called EnterEmpInfoJSP, which uses JSP tags to perform
the servlet's functions. We will explain the standard JSP action tags include and forward and the JSTL tags if and
choose . In addition, we will introduce Expression Language (EL). EL makes using tags even easier.
In our new architecture, we want EnterEmpInfoJSP to display all the EnterEmpInfoForm fields when it is initially
invoked with a get request. When the submit button is clicked, the EnterEmpInfoJSP will be invoked again but with
a post request. When EnterEmpInfoJSP receives a post request, the functionLB value should be retrieved and the
correct JSP invoked. Essentially the logic is:
If request is a get
Display EnterEmpInfoForm fields
If request is a post
Retrieve the selected function and forward to the correct JSP
Now there are two ways to create EnterEmpInfoJSP with all the required fields. We could copy EnterEmpInfoForm
(i.e., the HTML code contained in the body of the page) into EnterEmpInfoJSP.jsp. This would create the form and
all the components (i.e., text fields, labels, button, etc.) in the JSP. Or, we could include EnterEmpInfoForm.html in
EnterEmpInfoJSP.jsp using the JSP action tag include and change EnterEmpInfoForm's action from EmpServlet to
EnterEmpInfoJSP.
The include tag works as follows. When there is a request for a JSP, the container retrieves any resources specified
in an include tag and imbeds them in the response. Any changes made to the resource since the last request will
be reflected in the new request. In other words, the include tag allows dynamic content to be added to the JSP.
For example, the following include tag will embed the EnterEmpInfo.html file into a JSP:
<jsp:include page="EnterEmpInfoForm.html" flush="true"> </jsp:include>
If we ran the JSP, it would appear as in Figure 9-19 .
Figure 9-19.
 
Search WWH ::




Custom Search