The example in Form Basics shows a form that is defined in a single JSP. You might want to set the form’s dsp:form
tags in one JSP and define the form contents in another,, as in this example:
<%@ taglib uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0" prefix="dsp" %> <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c' %> <dsp:page> <html> <head><title>Form Entry</title></head> <body><h1>Form Entry</h1> <dsp:form action="/testPages/servbeantest.jsp" method="POST"> <dsp:include page="formbody.jsp/> </dsp:form> </body> </html> </dsp:page>
The embedded JSP formbody.jsp
contains the form’s input elements:
<%@ taglib uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0" prefix="dsp" %> <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c' %> <dsp:page> <p>Name: <dsp:input bean="/samples/Student_01.name" type="text"/> <p>Age: <dsp:input bean="/samples/Student_01.age" type="text" value="30"/> <p><dsp:input type="submit" value="Click to submit" bean="/samples/Student_01.submit"/> </dsp:page>
Note: An included page can contain element tags such as dsp:input
, dsp:textarea
, and dsp:select
only if the page is a complete JSP—that is, it imports the required tag libraries and contains the dsp:page
tag. Form elements cannot be embedded in a JSP fragment (.jspf
) file).
By separating a form’s dsp:form
tag from its actual contents, you can customize the form for different user types. For example, the dsp:form
tag might embed a Switch servlet bean that renders different forms for different genders—for example, specifies to include formbodyFemale.jsp
for female users and formbodyMale.jsp
for male users.