Create new JBoss Tools Documentation Jira issue

This will launch the Jboss Tools Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

Chapter 4. Coding the Various Files

4.1. Java Stub Classes
4.1.1. GetNameForm.java
4.1.2. GreetingAction.java
4.2. JSP Pages
4.2.1. inputname.jsp
4.2.2. greeting.jsp
4.2.3. index.jsp

We will now code both the Java stub classes just generated, the JSP files left in as placeholders from previous steps, and a new start JSP page we will have to create.

private String name = "";
this.name = "";
ActionErrors errors = new ActionErrors();

     return errors;

The final GetNameForm.java file should look like this:

package sample;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
public class GetNameForm extends org.apache.struts.action.ActionForm 
{
    
    private String name = "";
    
    public String getName() 
    {
        return name;
    }
    public void setName(String name) 
    {
        this.name = name;
    }
    
    public GetNameForm() 
    {
    }
    
    public void reset(ActionMapping actionMapping, HttpServletRequest request) 
    {
        this.name = "";
    }
    
    public ActionErrors validate(ActionMapping actionMapping, 
            HttpServletRequest request) 
    {
        ActionErrors errors = new ActionErrors();
        return errors;
    }
}
String name = ((GetNameForm)form).getName();

String greeting = "Hello, "+name+"!";
((GetNameForm)form).setName(greeting);
return mapping.findForward(FORWARD_sayHello);

The final version of GreetingAction.java should look like this:

package sample;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class GreetingAction extends org.apache.struts.action.Action 
{
    
    // Global Forwards
    public static final String GLOBAL_FORWARD_getName = "getName";
    
    // Local Forwards
    public static final String FORWARD_sayHello = "sayHello";
    
    public GreetingAction() 
    {
    }
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) throws Exception 
    {
        String name = ((GetNameForm)form).getName();
        String greeting = "Hello, "+name+"!";
        ((GetNameForm)form).setName(greeting);
        return mapping.findForward(FORWARD_sayHello);
    }
}

The last thing left to do is to code the JSP files whose editors should still be open from having been created as placeholders.

In this page, the user will enter any name and click the submit button. Then, the greeting action will be called through the form.


  • In the Insert Tag dialog box, type in name for property and select Finish

  • In the StrutsForm library in the JBoss Tools Palette, select submit , and drag it to right after the text box in the Visual pane of the editor

  • Right-click the submit button and select <html:submit> Attributes from the context menu

  • In the Attributes dialog box, select the value field and type in "Say Hello!" for its value

After tidying the page source, the Editor window for the file should look something like this: