Java Reference
In-Depth Information
logic in the servlet's doGet() method. Since both the HttpServlet.doGet() and
Action.execute() methods take an instance of HttpServletResponse as one of
their parameters, the technique to generate a report from an Action class is virtually
identical to the technique used when using a servlet.
Let us take a look at the JSP that will invoke the GenerateReportAction.execute()
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
"-//W3C//DTD HTML 4.01 Transitional//EN">
-//W3C//DTD HTML 4.01 Transitional//EN">
<title>Generate Report</title>
<p>Click on the button to generate the report.</p>
<html:form action="/generate_report">
This JSP will generate a very simple HTML form with a submit button as its only
input field.
Next, let us take a look at the form bean for this JSP.
package net.ensode.jasperbook.struts;
import org.apache.struts.action.ActionForm;
public class GenerateReportForm extends ActionForm
Since the HTML form generated by the preceding JSP has no input fields other than
a submit button, its corresponding form bean has no fields. We still need to write
it because when writing Struts applications, each JSP must have a corresponding
form bean.
To wire the Action class, the form bean, and the JSP together, we need to create a
struts-config.xml file and deploy it in the WEB-INF directory of the application's
war file.
Search WWH ::

Custom Search