Charles,
If you wish to simply display a
JSP without any processing,
you should declare a global forward as follows:
<global-forwards>
<forward name="aboutWillow" path="/form/aboutWillow.jsp"
</global-forwards>
If you do this, the link you set up should work just fine.
However, in most cases, you want to do some processing before displaying a JSP. For example, if aboutWillow.jsp is displaying data from a database, the struts way to do this is to create an action to do the work of getting the data from the database or (more properly) call other objects to get data from the database. It should then place the data into a form bean and then forward to the jsp, which will read or manipulate the information in the form bean.
If you want to do it this way, here is an example.
To declare the form do as follows:
<form-beans>
<form-bean name="AboutWillowForm"type="forms.AboutWillowForm">
</form-bean>
</form-beans>
You then create a
java class called forms.AboutWillowForm. It has to extend org.apache.struts.action.ActionForm. It's basically just a javaBean other than that, with fields and getters and setters for those fields. (example: private
String foo; public String getFoo() { return foo;} ... etc.)
To declare the action do as follows:
<action-mappings>
<action name="AboutWillowForm" path="/aboutWillowInit" scope="request" type="actions.AboutWillowInitAction">
</action>
</action-mappings>
You then write actions.AboutWillowInitAction. It has to extend org.apache.struts.action.Action and must have an execute() method that will be called by the struts framework. Here is a sample class:
package actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import forms.AboutWillowForm;
/**
* @version 1.0
* @author
*/
public class AboutWillowInitAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward(); // return value
AboutWillowForm aboutWillowForm = (AboutWillowForm) form;
try {
aboutWillowForm.setBar("Bar Bar");
aboutWillowForm.setFoo("Foo Foo");
request.setAttribute("AboutWillowForm", aboutWillowForm);
} catch (Exception e) {
// Report the error using the appropriate name and ID.
errors.add("name", new ActionError("id"));
}
// If a message is required, save the specified key(s)
// into the request for use by the <struts:errors> tag.
if (!errors.isEmpty()) {
saveErrors(request, errors);
// Forward control to the appropriate 'failure' URI (change name as desired)
//forward = mapping.findForward("failure");
} else {
// Forward control to the appropriate 'success' URI (change name as desired)
forward = mapping.findForward("aboutWillow");
}
// Finish with
return (forward);
}
}
Note the statement:
forward = mapping.findForward("aboutWillow");
This uses the global forward I showed you how to set up at the beginning of this message to actually display the aboutWillow.jsp.
Within the jsp, you can access "foo" and "bar" using the <bean:write> tag or the <html:text> tags using property="foo" or property="bar".
This seems complicated, but believe me, when creating complex web applications it keeps things organized and prevents the chaos you find when you try to put too much logic in the JSPs.