AJAX implementation in Struts 2 using JQuery and JSON
In this post, we will learn to implement AJAX calls from a JSP page to a Struts 2 Action class using JQuery and update the same JSP page back with the Json response from the Struts 2.
Library required
Since the response to be sent to jQuery is of type JSON, to handle it you need struts2-json-plugin-2.x.x.jar. This plugin allows you to serialize the Action class attribute which has getter and setter into a JSON object.
Steps done to set up our action for JSON
From the browser perspective: jQuery
jQuery allows you to issue an ajax request and expects a JSON object as a response.
Jsp Page
Now, let us create a JSP page with two drop down lists, one contains values for countries and the other that is going to be populated with values for states based on the value selected in the first drop down list. This is done without a page refresh, by making AJAX calls to the Struts 2 action on first drop down list change event.
Recommended reading :
<%@ taglib prefix="s" uri="/struts-tags"%>AJAX in Struts 2 using JSON and jQuery AJAX calls to Struts 2 using JSON and jQuery
Note that I have referenced jQuery files in the head section of the jsp which is responsible for the AJAX call made to the struts 2 action and for displaying the response back in the JSP.
Whenever the value is selected in the “country” drop down list, its change event is fired and the ‘getJSON’ function executes ajaxAction (first argument of ‘getJSON’) configured in struts.xml. I have explained about the parameters of ‘getJSON’ method in the article here.
From the server’s perspective: Struts 2
In action class you need to create instance variables and its respective getter and setter methods. Here all the variables that have a setter can be set to the values received as parameters from jQuery and all the variables that have a getter method can be retrieved in the client javascript code.
Also read :
Action class
package com.action; import java.util.LinkedHashMap; import java.util.Map; import com.opensymphony.xwork2.Action; public class AjaxJsonAction implements Action{ private MapstateMap = new LinkedHashMap (); private String dummyMsg; //Parameter from Jquery private String countryName; public String execute() { if (countryName.equals("India")) { stateMap.put("1", "Kerala"); stateMap.put("2", "Tamil Nadu"); stateMap.put("3", "Jammu Kashmir"); stateMap.put("4", "Assam"); } else if (countryName.equals("US")) { stateMap.put("1", "Georgia"); stateMap.put("2", "Utah"); stateMap.put("3", "Texas"); stateMap.put("4", "New Jersey"); } else if (countryName.equals("Select Country")) { stateMap.put("1", "Select State"); } dummyMsg = "Ajax action Triggered"; return SUCCESS; } public Map getStateMap() { return stateMap; } public String getDummyMsg() { return dummyMsg; } public String getCountryName() { return countryName; } public void setStateMap(Map stateMap) { this.stateMap = stateMap; } public void setDummyMsg(String dummyMsg) { this.dummyMsg = dummyMsg; } public void setCountryName(String countryName) { this.countryName = countryName; } }
In the above code, we create a maps and populates its value based on the country parameter passed to the action class by the AJAX call made by the JQuery’s getJSON() method.
struts.xml
Since the response needed by jQuery is of type json, so we need to convert this map objects to json strings, for this you need to configure this Action class in struts.xml such that it returns a json object. This configuration is as follows:
Create a package in struts.xml file, which extend json-default and specify the result type of your action class inside this package to be json. The json-default package contains an interceptor and the result type configuration for JSON requests and responses.
true true
Note: json-default package extends struts-default
Web.xml
Struts2 struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* index.jsp
Recommended Article :
Demo
On selecting ‘India’ in the first dropdown list
On selecting ‘US’ in the first dropdown list
What wrong with this code
Insert title here
$(document).ready(function () {
$(‘#userCheck’).change(function (event) {
if(!$(this).is(“:checked”))
return;
var referenceNumber = $(‘#first’).val();
if(referenceNumber != “”){
$.get(‘populateTextBox’,
{ “first” : referenceNumber},
function (responseText)
{
//console.log(“response”, responseText);
$(‘#second’).val(responseText);
});
}
});
});
Struts.xml
/index.jsp
<!– –>
Action class
package com.pradee.demo;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
public class DemoAction extends ActionSupport implements ServletRequestAware {
HttpServletRequest request;
private Person person;
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public String execute() {
String requestID = getServletRequest().getParameter(“first”);
System.out.println(requestID);
if(requestID.equals(“7”))
{
person.setFirst(“pradeep”);
person.setSecond(“kumar”);
}
return “success”;
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public HttpServletRequest getServletRequest() {
return this.request;
}
}
hi sir am getting Error: Could not find action or result: /ProjectName/Action?variable=value+value
There is no Action mapped for namespace [/] and action name [actionName] associated with context path
when I select value from select option
Without using this funtion each(jsonResponse.stateMap, function(key, value),
How I can get specific value inside javascript like var val=
jsonResponse.stateMap[1].key
Hi, I have four drop downs in which based on first drop down being selected, second one should be generated dynamically from database, again based on second selection, the other 2 drop downs should be populated. And the issue that i am facing here is …i am able to fetch those values in console but not in the front end. Please help me in this issue.
hi how to retain the drop down values generated through ajax , even after form submit
hi , thanks for the example. Its working perfectly for me but when i submit the form , i lose the generated drop down values. I am using STRUTS2 framework. I tried to store the generated values in a session attribute. But i have observed that the $.getJSON(“ajaxAction… does not get called if we are selecting a vlue that was previously selected. But it is able to display the related dropdowns.
hashmap: => {1=Home,2=Enrollment}
// printing Home Enrollment …..as menu
==============================================
If I click on “Home” I want to pass “1” to action class using ajax. and retrieve data from action class.(data in action class is ready just i want ajax code in jsp how can i pass key?? )
onclick or hover I want to retrieve that key related data. my business logic is ready just want ajax call. Can i call method of action class from ajax???
Is it possible? if i click on link how will i get key and pass it dyanamically?
Yes it is possible
Hi Sir, Can you send me ajax code or any example on this [email protected] .I don’t know ajax.
how can I use using hashmap from action class and how will I get sub menus?
Hi the above is the example for implementing ajax in struts 2, you just need to change this code a little for your scenario.
how can I use sj menu tag
which tag should I use instead of select tag
I want to create submit buttons or links dynamically using iterator tag and based on button dynamic method of action class must be called. how can i create using this:
here hrMenu is HashMap….
/EmpSuccess.jsp
0
Its working fine for me..
But when I am trying to call the popup with ajax response value, nothing is displaying there. what to do in this case?
I am getting below error
There is no Action mapped for namespace / and action name ajaxAction. – [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
it seems like you havent configured your action in the struts.xml file, the error “There is no Action mapped for namespace / and action name ajaxAction. – [unknown location]” means that no action tag is configured with name “ajaxAction”
use namespace=”/” attribute in package tab above
Hi I tried this example and it works fine for me. But when I implement the same method in my project the action has been called but we could not get any response to the jsp. If we have no result defined in struts.xml for our action, we are at least getting the jsonresponse as null. We are also using tiles. As you have mentioned above should we combine struts-default and tiles-default interceptors and extend into out struts package? If so can you please post an example or share any link to combine two defaults?
Hi, Yes you have to create a new interceptor by combining those two interceptor. As an alternate you can use the response’s PrintWriter as shown below.
[code]
public String execute()
{
Gson gson = new Gson();
String jsonString = gson.toJson(someMethods(parameter));
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType(“application/json”);
response.getWriter().write(jsonString );
return null;
}
[/code]
For this approach you dont need to combine those interceptors.
And set the result type in struts.xml to NOTHING.
Thanks a lot, this method works fine without combining any interceptors. Please share link if you have written any blog on interceptors too to try the other approach. Thanks again :)
Sure, but the above method is not recommended in struts 2 project.
hello, I’m trying to work wity your code.I have a problem, the jsp showed , but when I select the country field, it doesnt work, because the select does nothing
what can i do?
the struts.xml its ok, the Java File is equals to your example
Maybe I would to download other Library to JavaScript , or what do you think?
Have you referred the jquery library properly ?
how can one pass value of item from action class to jsp file through ajax call?
Hi Mohaideen,
I am working on Struts2 and jQuery currently for a web application and I have a requirement where I need to use AJAX along with S2 and jQ. Requirement is that I have a list of aBeans object, where each aBean has a list of bBeans objects and a list of cBeans object along with other fields of aBeans.
When the form is loaded, I display the list of aBeans as a table where one of the columns has links named BB and CC. Assume there are 10 aBeans object and they are shown as 10 rows in a table. When I click the link BB in the first row, I have to make a AJAX call and return the list of bBeans and display under the first row. When I click the link BB again, it has to hide. It applies to the link CC, which on click, will fetch and display the list of cBeans objects. Hope I explained it correctly. I tried with different approaches:
Approach – 1:
Make the AJAX call using jQuery, but the issue is that I get the list of bBeans as JSON, I dont know how to attach the list of the respective aBean object. Kind of stuck after getting json data from Action class.
Approach – 2:
Make the AJAX call using struts-jquery plugin. I get the data on the screen, but could not attach it to the original aBean object.
Can you please fix my problem or suggest me an approach to solve this?
Regards,
Anand…
Hi this scenario can be implemented via jTable plugin(master/child tables).. I have implemented a simple one in struts 2 http://www.simplecodestuffs.com/pagination-in-struts-2-using-jquery-jtable-plugin/
Please refer jTable official website(http://jtable.org/) for master/child table configuration
hey bro when i storing states to data base…im getting key but not values how to get values plz help me??
Just replace key with value as shown below.
[code] $(‘
its not working for me
Hi,
Your coding and explanation is very good and clear. I’m working with struts 2 & hibernate.
As explained by you, everything is working fine if static data is set to the Map similarly as shown in your example. But the same is not working when I’m trying to retrieve data from database and set to the Map.
Please help me with this.
I tried this example. But I got a 404 error. Some action mapping error happened. I changed the action as $.getJSON(‘ajaxAction.action’, in index.jsp, I mean I have added .action, then it worked fine. Can you please explain me is it mandatory to put .action? If not how can I solve the 404 error.
In older version of struts 2, the default extension for any input request is .action, the new version of struts 2 does not have any extension at all. May be you are using the older version……
visit http://www.simplecodestuffs.com/struts-2-custom-extension-example/ for more info..
the code is working fine but i try to populated from the database but it is not working i don’t know why
Can you share you war file ?? .. Upload it in drop-box and let me know
I am using tiles framework then how can i return json object to my jsp.
registerdef
Hi you can try to combine the interceptor in tiles-default and struts-default and create a new interceptor, and extend it in your struts package, I guess this method will work.
Hi I am still facing issues while integrating S2 tiles with JSON. My action is not getting callled. can you please provide me source code for this. Thanks.
Thank you so much…………it helped me a lotttttttttttttttttttt…………………….
I am using the code, but the second select does not appear the values that were placed on the array stateMap in Action. It is not supposed to appear?
Hi sousa,
Please build and clean your project, most times, this problem usually occurs with IE browsers. In case of IE Ajax call works fine for first time but not working rest of the time. This comes because, internet explorer cache the response of the ajax call and when you will make call to same url,It just show the cached response. To avoid this we have to make fool to ie by changing the same ajax call URL each time by adding one more false parameter like psuedoParam=new Date().getTime().So each time the URL will be a new URL so the response will not cache.
Also I have updated the latest code in dropbox, which is available in the link – https://www.dropbox.com/s/6mzmbhgtvo0pl3f/JqueryJsonStruts2.war, Please use this file and let me know if issues occurs again
I’m not using IE browsers, but I’m using a different version of struts as well as the other’s jar(commons, etc). Will this be the problem? I went back to download and still does not show, nor the first time. I’m using Chrome.
Try to run it in incognito window.(Open chrome and press ctrl+shift+N). And do you mean even the war file I uploaded recently is not working for you ?.. If the issue still occurs then please upload the code in dropbox and share me the link.
https://www.dropbox.com/s/4h3808nm2w22ddq/testeAjax.rar
hi change your filter in web.xml to
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter instead of org.apache.struts2.dispatcher.FilterDispatcher and I found out that you have given action name to be “ajaxAction” in jsp where else in file example.xml you have given it as “helloworld”, now modify it to ajaxAction, then this program will work. let me know if it works .
I have done all the changes, but still does not work :(
But your code is working from my end with those changes. I’m not sure what else you are missing.
Is working.Thank you very much :)
Glad that it worked:)
Jun 03, 2014 9:30:35 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [/JqueryJsonStruts2] threw exception [Filter execution threw an exception] with root cause
java.lang.NoClassDefFoundError: org/apache/commons/lang/xwork/StringUtils
at org.apache.struts2.json.SerializationParams.(SerializationParams.java:57)
at org.apache.struts2.json.JSONResult.writeToResponse(JSONResult.java:214)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:204)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Hi Vipul,
Please include struts2-json-plugin-2.x.x.jar in your workspace.
I wil update the war file in short time and let you know.
Jun 03, 2014 9:30:35 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [/JqueryJsonStruts2] threw exception [Filter execution threw an exception] with root cause
java.lang.NoClassDefFoundError: org/apache/commons/lang/xwork/StringUtils
at org.apache.struts2.json.SerializationParams.(SerializationParams.java:57)
at org.apache.struts2.json.JSONResult.writeToResponse(JSONResult.java:214)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:204)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Hi Vipul,
Please include struts2-json-plugin-2.x.x.jar in your workspace.
I wil update the war file in short time and let you know.
Hi Mohaideen
Please help me out as i got Null Pointer Exception and when i select country than i dont get states
Very Important (If you want to transfer data from Action Class to JQuery)
Without these 3 jar files you can not pass variable from Action Class to JQuery.
json-simple-1.1.jar
struts2-json-plugin-2.3.1.2.jar
commons-lang-2.6.jar
Struts.xml
jsonData