Chapter 7. Application development 149
2. Create an input page with an HTML form, for example, input.jsp. Make it a
JSP so it can provide dynamic information, for example, using JSP taglibs, or
provide error messages when validation fails.
The WebSphere Studio wizard that creates JSPs (
File -> New -> JSP File)
gives you the option of selecting a model on which to base the JSP. Be sure
to select
Struts JSP for this JSP and the next two JSPs. This will include the
taglib directives to the Struts tag libraries.
Example 7-1 input.jsp
<%@ page language="java" %>
<!-- include all the JSP Taglibs needed -->
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-form.tld" prefix="form" %>
<html>
<body>
<!-- print out the errors, if any -->
<html:errors/>
<!-- create a form -->
<html:form action="/sampleaction.do" focus="userid">
<!-- get the value for prompt.name from the applicationresources.properties -->
<bean:message key="prompt.name"/>:
<!-- create a text input field -->
<html:text property="name" size="20">
<!-- create a submit button -->
<html:submit>Submit</html:submit>
</html:form>
</body>
</html>
3. Create a Results page with dynamic content, for example, results.jsp.
Example 7-2 results.jsp
<html>
<body>
This is the result page.
<!-- Check out the Struts documentation on how to use the form-bean here to
dynamically retrieve information from the bean. Also check the Struts taglibs
-->
</body>
</html>
4. Create an error page to indicate errors, for example, error.jsp.