Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you start Tomcat (or whichever J2EE container you are using) and type in * http://localhost:8080/hello-world.action*Image Modified in to your browser you should see our JSP. This illustrates that SmartURLs will find results ever when no action exists and it is all based on the URL passed to Struts.

Code behind hello world

Let's expand on this example and add a code behind class. In order to do this we first have to tell SmartURLs where the classes live. This is controlled via the property smarturls.action.packages setting in the struts.properties file. If you don't have a struts.properties file, simply create one and place it into the classpath of the application. This can be done by putting the file in WEB-INF/classes or into a JAR file in the root directory of that JAR file. Here's how it should look:

Code Block
titlestruts.properties
borderStylesolid

smarturls.action.packages=com.example.actions

This configuration tells SmartURLs to go find all the actions in the com.example.actions package and configure them for use. This will also find all actions in sub-packages as well. We'll get to sub-packages and namespaces next. Here's our code behind:

Code Block
titlecom.example.actions.HelloWorld
borderStylesolid

package com.example.actions;

import 

public class HelloWorld extends ActionSupport {
  private String message;

  public String getMessage() {
    return message;
  }

  public String execute() {
    message = "Hello World!"
    return SUCCESS;
  }
}

Sub-packages and namespaces

Configuration reference