2

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.

B. Desai
  • 16,414
  • 5
  • 26
  • 47
Achaius
  • 5,904
  • 21
  • 65
  • 122
  • 1
    http://stackoverflow.com/questions/916285/cant-set-struts2-result-type-to-json – Ninad Pingale Jul 02 '14 at 09:27
  • I am new to sruts. Can you point me how to add class information in action results annotation as per the above stackoverflow link – Achaius Jul 02 '14 at 09:40
  • 1
    You should provide it if needed to the parent package, at the moment Struts2 doesn't have annotation based configuration equivalent. – Roman C Jul 02 '14 at 10:24
  • possible duplicate of [jQuery Ajax - issue returning JSON value](http://stackoverflow.com/questions/17093862/jquery-ajax-issue-returning-json-value) – Roman C Jun 11 '15 at 17:59

2 Answers2

2

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.

Progster219
  • 85
  • 10
0
  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.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243