Reputation: 351
I have been trying to display my JSON
data returned from action class in my JSP
, but in vain...
I am using struts 2.1.8
..
The following is the struts.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>
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources"> </constant>
<package name="sampleStrutapp" extends="struts-default">
<action name="login" class="struts2.LoginAction">
<result name="success">/checkValidation.jsp</result>
<result name="error">/HelloWorld.jsp</result>
</action>
</package>
<package name="struts2" extends="json-default">
<action name="populate" class="struts2.Populating">
<result type="json">
<param name="root">popdata</param>
<param name="noCache">true</param>
</result>
</action>
</package>
</struts>
My action class is the following..
package struts2;
import java.util.List;
import com.opensymphony.xwork2.*;
import net.sf.json.JSONObject;
import org.apache.catalina.connector.Request;
import data.Details;
import com.Various_functions;
public class Populating extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
public String usrname;
public String email;
public String lang;
public String gender;
public String comp;
public String desg;
public int rownum;
public int row;
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
private String popdata;
public String getPopdata() {
return popdata;
}
public void setPopdata(String popdata) {
this.popdata = popdata;
}
public int getRownum() {
return rownum;
}
public void setRownum(int rownum) {
this.rownum = rownum;
}
public String execute(){
Various_functions funct = new Various_functions();
List<Details> dev = funct.populate(this.getRow());
this.popdata = dev.get(0).getCompName()+","+dev.get(0).getDesig()+","+dev.get(0).getEmailId()+","+dev.get(0).getGender()+","+dev.get(0).getLang()+","+dev.get(0).getUserName();
System.out.println("In action class");
return "success";
}
public String getUsrname() {
return usrname;
}
public void setUsrname(String usrname) {
this.usrname = usrname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLang() {
return lang;
}
public void setLang(String lang) {
this.lang = lang;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getComp() {
return comp;
}
public void setComp(String comp) {
this.comp = comp;
}
public String getDesg() {
return desg;
}
public void setDesg(String desg) {
this.desg = desg;
}
}
and my javascript is the following..
function populate(rownum){
alert(rownum);
var inputData = { "row" : 1
};
// alert(inp);
$.post('populate.action', inputData, populatecallback, "json");
}
function populatecallback(popdata) {
alert("in call back!!");
var result = popdata.split(",");
usrname= result[5];
email= result[2];
desg= result[1];
lang= result[4];
comp= result[0];
gender= result[3];
$('#txtName').val(usrname);
$('#txtEmail').val(email);
$('#txtCmp').val(comp);
$('#txtDesg').val(desg);
$('#lan').val(lang);
$('#gen').val(gender);
}
Now, the jquery post is not working.
The following is the current library structure..
commons-collections-3.1.jar, commons-fileupload-1.2.1.jar, commons-io-1.3.2.jar, commons-logging-1.1.1.jar, freemarker-2.3.15.jar, slf4j-api-1.5.8.jar, slf4j-simple-1.5.8.jar, struts2-core-2.1.8.1.jar, struts2-jquery-plugin-1.8.3.jar, xwork-core-2.1.6.jar
My js files are the following..
jquery-1.6.4.min.js, json.js
Suggestions appreciated.
Thanks and regards, hemanth.
Upvotes: 0
Views: 1043
Reputation: 160321
The exception is caused by a library version mismatch; in your case you're deploying multiple versions of XW, which is even worse. S2.1.8.1 requires xwork-core 2.1.6. Having both on the path is a bad idea. Consider using Maven to handle your dependency management, and avoid these kinds of headaches.
I did not verify the remaining versions on your list; you need to do so. The easiest way is to use Maven, or check against something like mvnrepository.com (where I got the S2.1.8.1 XW dependency from).
Upvotes: 1
Reputation: 5551
Might not be relevant now, but back in 2009, there was an issue with Struts and writing json, namely:
http://code.google.com/p/jsonplugin/issues/detail?id=91
Perhaps its a similar issue you are hitting.
Upvotes: 1