You want to
Use the c:import JSTL core tag.
The previous recipe described how to
into a servlet's HTML input. It is very easy to
accomplish the same task in a JSP, such as by using the
importMod.jsp file shown in Example 12-3. This JSP uses the JSTL core tag
c:import to include a file named
functions.js module contains a
definitions (Example 12-1 in Recipe 12.1). The HTML
generated by the JSP shows that the c:import
action positioned the script tag within the
JSP's head tag. The JSP generates
the HTML form shown previously in Figure 12-1.
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<h2>Enter Your Name and Email</h2>
<form action="/home/displayHeaders.jsp" name="entryForm"
<table border="0"><tr><td valign="top">
First and last name: </td> <td valign="top"><input type="text" name="name" size="20"></
Email: </td> <td valign="top"><input type="text" name="email" size="20"></td></tr>
<tr><td valign="top"><input type="submit" value="Submit"></td>
When the user submits the HTML form, her action is intercepted by the
event handler, which does a basic
syntax check on the email address the user typed into the form. The
form submit, targeted to a /home/
displayHeaders.jsp page, is cancelled if the submitted
email address has the wrong syntax.
String that the user typed into the text field
named email. The keyword this
refers to the form object, which contains the
parameter of this event handler.
validate form input in a JSP; Recipe 12.3 on
Recipe 12.5 on validating form values with a
a filter with HTTP requests.