Java Reference
In-Depth Information
In the previous section, we created a login form on both the
login.jsp
and
loginerror.jsp
pages. If we wish to change the look of this login form, we would
have to do it twice, once in each page. This form is a perfect candidate to be extracted
to a JSP fragment.
Creating a JSP Fragment in NetBeans
To create a JSP fragment in NetBeans, we simply need to go to
File | New
, select
Web
as the category, then
JSP
as the file type. We then fill out all the information
in the
New JSP File
window as usual, making sure to check the
Create as
JSP Segment
checkbox.
NetBeans suggests placing the JSP fragment under
WEB-INF/jspf
. The reason for
this is that any files under the
WEB-INF
folder are not directly accessible via the web
browser. Since JSP fragments are not full JSPs, most of the time they won't render
properly in a web browser by themselves, therefore it is a good idea to follow
NetBeans' suggestion.
NetBeans will automatically create the
WEB-INF/jspf
folder for us if it
doesn't already exist.