Tyring a simple example of json but it is showing error. I have included gson-2.2.3.jar in class path.
I am using netbeans 7.1. This program is not deploying.
Apache tomcat log is showing:
Unable to load configuration. - action - file:/D:/APP/webApp1/build/web/WEB-INF/classes/struts.xml:10:73
Caused by: Error building results for action sayHi in namespace - action - file:/D:/APP/webApp1/build/web/WEB-INF/classes/struts.xml:10:73
Caused by: There is no result type defined for type 'json' mapped with name 'success'. Did you mean 'json'? - result - file:/D:/APP/webApp1/build/web/WEB-INF/classes/struts.xml:11:33
I am trying simple example. Please see what is the proble. Action Class
public class AjaxActions extends ActionSupport {
private String name;
private String greeting;
public String sayHi() {
greeting = "HI " + name;
return ActionSupport.SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGreeting() {
return greeting;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
Struts.xml
<package extends="struts-default,json-default" name="ajax-package" namespace="/ajax">
<action class="example.AjaxActions" method="sayHi" name="sayHi">
<result type="json">
</result>
</action>
</package>
in jsp file
<form action="" id="introForm">
<label for="name">Enter Your Name</label>
<input name="name">
<input type="submit">
</form>
<script>
$(function(){
$("#introForm").submit(function(){
var formInput=$(this).serialize();
$.getJSON('ajax/sayHi.action', formInput,function(data) {
$('.result').html('' + data.greeting + '');
return false;
});
});
</script>