Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:54:05+00:00 2026-06-04T12:54:05+00:00

I’m trying to use Json with struts 2 and jquery, I am able to

  • 0

I’m trying to use Json with struts 2 and jquery, I am able to do it up to a level but I have been stucking in some problem for last two days. Here are the codes and configuration that i’ve used for this

<package name="default" extends="struts-default,json-default" namespace="/">    

    <result-types>
        <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"></result-type>
    </result-types>

    <action name="showUpdateAjax" class="courseCreateAction" method="showUpdateAjax">
            <result type="json">
                <param name="includeProperties">courseInfo, fetchedAllSubjects, selectedFetchedSubs, subjectList, fetchedAllExamType, examTypeList, selectedExmTypes, fetchedAllCourse, isUpdate, btnPressed, updateCourseId, nextCourse, previousCourse</param>
                <param name="prefix">true</param>
                <param name="ignoreHierarchy">false</param>
            </result>
    </action>

Here is my Jsp codes for this part

<tr><td><input type="submit" value="Refresh" onclick="refreshData()" id="refreshBtn"/></td></tr>

    <tr><td><s:a href="/SASIS/showUpdateAjax.action?updateCourseId=4">click Here 2</s:a></td></tr>
</table>
</center>
<script type="text/javascript"> 
    $(document).ready(function(){
            $("#refreshBtn").click(function(){
                $.getJSON("/SASIS/showUpdateAjax.action?updateCourseId=4",function(data){
                    alert('its working '+data);

                    });

                });
        });
</script>

And here is my java code

public class CourseCreateAction extends ActionSupport implements ServletRequestAware{
private CourseInfo courseInfo;
private List fetchedAllSubjects;
private List<SubjectInfo> selectedFetchedSubs;
private List subjectList;
private List fetchedAllExamType;
private List examTypeList;
private List<ExamType> selectedExmTypes;
private List fetchedAllCourse;
private String nextCourse;
private String previousCourse;
private DAOInterface dao;
private String btnPressed;
private String updateCourseId;  
private HttpServletRequest request; 
private boolean isUpdate;

public void setServletRequest(HttpServletRequest request) {
    request=request;
}

public List getFetchedAllSubjects() {
    return fetchedAllSubjects;
}

public void setFetchedAllSubjects(List fetchedAllSubjects) {
    this.fetchedAllSubjects = fetchedAllSubjects;
}

public List<SubjectInfo> getSelectedFetchedSubs() {
    return selectedFetchedSubs;
}

public void setSelectedFetchedSubs(List<SubjectInfo> selectedFetchedSubs) {
    this.selectedFetchedSubs = selectedFetchedSubs;
}

public List getSubjectList() {
    return subjectList;
}

public void setSubjectList(List subjectList) {
    this.subjectList = subjectList;
}

public CourseInfo getCourseInfo() {
    return courseInfo;
}

public void setCourseInfo(CourseInfo courseInfo) {
    this.courseInfo = courseInfo;
}
public List getFetchedAllExamType() {
    return fetchedAllExamType;
}

public void setFetchedAllExamType(List fetchedAllExamType) {
    this.fetchedAllExamType = fetchedAllExamType;
}

public List getExamTypeList() {
    return examTypeList;
}

public void setExamTypeList(List examTypeList) {
    this.examTypeList = examTypeList;
}

public List<ExamType> getSelectedExmTypes() {
    return selectedExmTypes;
}

public void setSelectedExmTypes(List<ExamType> selectedExmTypes) {
    this.selectedExmTypes = selectedExmTypes;
}

public List getFetchedAllCourse() {
    return fetchedAllCourse;
}

public void setFetchedAllCourse(List fetchedAllCourse) {
    this.fetchedAllCourse = fetchedAllCourse;
}

public String getNextCourse() {
    return nextCourse;
}

public void setNextCourse(String nextCourse) {
    this.nextCourse = nextCourse;
}

public String getPreviousCourse() {
    return previousCourse;
}

public void setPreviousCourse(String previousCourse) {
    this.previousCourse = previousCourse;
}

public DAOInterface getDao() {
    return dao;
}

public void setDao(DAOInterface dao) {
    this.dao = dao;
}

public String getBtnPressed() {
    return btnPressed;
}

public void setBtnPressed(String btnPressed) {
    this.btnPressed = btnPressed;
}

public String getUpdateCourseId() {
    return updateCourseId;
}

public void setUpdateCourseId(String updateCourseId) {
    this.updateCourseId = updateCourseId;
}

public boolean getIsUpdate() {
    return isUpdate;
}

public void setIsUpdate(boolean isUpdate) {
    this.isUpdate = isUpdate;
}

public String showUpdateAjax(){
        try{
        System.out.println("Ajax calling...........");
        showUpdateCourse();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }

public String showUpdateCourse(){
    try {
        isUpdate=true;
        courseInfo=dao.getCourse(Integer.parseInt(updateCourseId));
        System.out.println(courseInfo.getCourseId());
        selectedFetchedSubs=courseInfo.getSubjectList();
        selectedExmTypes=courseInfo.getExamTypeList();
        fetchedAllSubjects=dao.getAllSubjects();
        fetchedAllExamType=dao.getActiveExamTypes();
        for(ExamType exmType:selectedExmTypes)
            for (int i = 0; i < fetchedAllExamType.size(); i++) {
                if(exmType!=null&&((ExamType)fetchedAllExamType.get(i)).getExamTypeId()==exmType.getExamTypeId()){
                    fetchedAllExamType.remove(i);
                    break;
                }
            }
        for(SubjectInfo subInfo:selectedFetchedSubs)
            for (int i = 0; i < fetchedAllSubjects.size(); i++) {
                if(subInfo!=null&&((SubjectInfo)fetchedAllSubjects.get(i)).getSubjectId()==subInfo.getSubjectId()){
                    fetchedAllSubjects.remove(i);
                    break;
                }
            }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return SUCCESS;
}

I have used spring and hibernate in project as well. While doing this when I click on the link which is calling the showUpdateAction.action I got response like this

{}&& {"btnPressed":null,"courseInfo":{},"examTypeList":null,"fetchedAllCourse":[],"fetchedAllExamType":[],"fetchedAllSubjects":[],"isUpdate":true,"nextCourse":null,"previousCourse":null,"selectedExmTypes":[],"selectedFetchedSubs":[],"subjectList":null,"updateCourseId":"4"}

But when I click on the button its not showing anything, but the function is called. Moreover here CourseInfo is an object where there are variables with setter getter methods and this object is state full when the showUpdateAction.action is called, but in the output we can see the courseInfo is with empty curly braces. Please help to solve this problem I have gone through several posts and googled a lot. Now I have no option except asking. Please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:54:06+00:00Added an answer on June 4, 2026 at 12:54 pm

    Thank you for your replies Mr. mprabhat and Mr. Rahul. I used firebug to debug this problem, as Rahul told me to use webinspector for the purpose, as I am using firefox I preferred firebug. And I did really get help to solve the jquery problem as suggested by mprabhat.

    Now, the actual problem was with struts-jquery plugin and spring. In my code for ‘dao’ the object is injected through spring. While json plugin was trying to serialize the object it founded a method of the database object with public access modifier. Which somehow creates all the problems. I got an exception like below while trying to return the json without ‘includeProperties‘ param

    org.apache.struts2.json.JSONException:  
    org.apache.struts2.json.JSONException:  
    org.apache.struts2.json.JSONException:  
    org.apache.struts2.json.JSONException: java.lang.IllegalAccessException:  
    Class org.apache.struts2.json.JSONWriter can not access a member of class  
    org.hibernate.persister.entity.AbstractEntityPersister$3 with  
    modifiers "public"
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:230)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126) 
    

    Therefore I decided to exclude the property ‘dao’ in my struts configuration instead of including the rest of the properties.

    <action name="showUpdateAjax" class="courseCreateAction" method="showUpdateAjax">
        <result type="json">
            <param name="excludeProperties">dao</param>
            <param name="ignoreHierarchy">false</param>
            <param name="excludeNullProperties">true</param>
        </result>
    </action>
    

    And the problem is solved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.