Achaius
Achaius

Reputation: 6124

How to create struts action with result type as "json"

I created the following action

@Action(value = "searchPersonByName", results = {@Result(type = "json",
    params = {"status", "204" }) })
public List<Person> searchPerson() {
    return new ArrayList<Person>();
}

Deploying struts application with this action throws the following error

Caused by: The Result type [json] which is defined in the Result annotation on the class [class com.mk.gk.actions.PersonAction] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [com.mk.gk.actions#/#/] - [unknown location]

I want to call this action in jquery.ajax with dataType as "json". How to achieve this? How to get this action type as json.

Upvotes: 2

Views: 2051

Answers (2)

Progster219
Progster219

Reputation: 85

Struts2 now supports specifying the parent package through annotations. Consequently, this error can also be resolved by adding the annotation @ParentPackage("json-default") to your class, assuming you are using the Convention Plugin, which is now common practice.

Upvotes: 2

Andrea Ligios
Andrea Ligios

Reputation: 50203

  1. Include Struts2-Convention-Plugin
  2. Include Struts2-JSON-Plugin
  3. In you struts.xml, make your Package extending json-default.

Check out the Struts2-jQuery-Plugin too, to perform jQuery stuff easily.

Upvotes: 0

Related Questions