Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add example for JSON result configuration with convention plugin

...

  1. Add the map inside a package that extends "json-default"
  2. Add a result of type "json"

Example with Convention Plugin Configuration:

Code Block
JAVA
JAVA

import java.util.HashMap;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Result;

@Result(type = "json")
public class JSONExample extends ActionSupport {
// action code
}

Example with XML Configuration:

Code Block
XML
XML
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

  <package name="example"  extends="json-default">
     <action name="JSONExample" class="example.JSONExample">
        <result type="json"/>
     </action>
  </package>

</struts>

...