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 8553783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:43:56+00:00 2026-06-11T14:43:56+00:00

Possible Duplicate: How use $.ajax() method in struts2 simply, 1 .can sombody tell me

  • 0

Possible Duplicate:
How use $.ajax() method in struts2

simply,

1.can sombody tell me how to call a struts action through jquery ajax?(not struts jquery plugin)

2.and how can get results and how can send html output(result) to a target div correctly?

3.should we change the result types in struts configurations?

4.how to run javascript after ajax content have loaded?

5.and any other things i should have known about struts actions regarding jquery ajax and javascript running.

please somebody can share a best reference for this or clean answer.

  • 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-11T14:43:58+00:00Added an answer on June 11, 2026 at 2:43 pm

    Although you can find bits and pieces of this information on the net easily. Let’s put it at same page.

    Ans 1::Include the js file of JQuery and Write your ajax call.

    $(document).ready(function() {
    $.ajax({
        type: "POST",   //Default is GET
        cache : false, 
        data: sendingData,           //Data you need to send if in JSON format
        dataType: 'json',     //If json is required
        contentType: 'application/json; charset=utf-8',
        url: "MYACTIONNAME.action",          //URL you need to pass
        success: function(value) {
            alert(value.properties);        
        },
        error: function (xhr, ajaxOptions, thrownError) {
            $(".errors").html("Please Try Again");
            //console.log(xhr.status + thrownError);
        }
    });
    

    });

    That is for sending JSON and retrieving JSON from action class.
    Configuration of JSON can be found here along with other answers

    Ans 2::

    $(document).ready(function() {
            $("#div").load("MYActionName.action"); //can do that through $.ajax also
    });
    

    If you want to show only part of the loaded HTML(converted JSP) , use

    $("#divToReplaceWithNewOne").hide().load('MyActionName.action #newDivWhichWillbeFilled').fadeIn(1000);  //with animation
    

    Ans 3:: It all depends on what you want . You have to configure if you want pdf or other thing.

    a) Whole JSP

    <action name="MYActionName" class="MYActionNameBean" method ="execute">
                <result name="success" type="dispatcher">
                    <param name="location">/jsp/MyNewPage.jsp</param>
                </result>
            </action>
    

    b) Working with streams and setting content through ActionClass only

    <action name="MYActionName" class="MYActionNameBean"    method="execute">
                <result type="stream">
                        <param name="contentType">text/html</param>
                        <param name="inputName">inputStream</param>
                </result>
            </action>
    

    Method::

    public String execution() throws Exception {
            try{
                PrintWriter outWriter = null;
                StringBuffer sbf = new StringBuffer("");
                HttpServletResponse httpResponse = ServletActionContext.getResponse();
                try {
                    outWriter = httpResponse.getWriter();
                                            sbf.append("String to be sent to View");
                        }
    
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                finally{
    
                    if(outWriter!=null){
                        httpResponse.setContentType("text/html");
                        outWriter.println(sbf.toString());
                        outWriter.flush();
                        outWriter.close();
                    }
                }
    
            }catch (Exception e) {
                throw new MyOwnException(e);
            }
            return null;
            }
    

    c) With JSON as result. (struts2-json plugin)

    <action name="MYActionName" class="MYActionNameBean"    method="execute">
                <result type="json"></result>   
            </action>
    

    d) PDF

    <action name="DownloadPdf" class="PrintPdfActionBean" method="executeViewPdf">
                <result name="success" type="stream">
                    <param name="contentType">application/pdf</param>
                    <param name="inputName">fileInputStream</param>
                    <param name="contentDisposition">attachment; filename="${fileName}.pdf"</param>  //filename is variable in action class
                    <param name="bufferSize">4096</param>
                </result>
            </action>
    

    Ans::4. Thats all JQuery In success/done/deferred callbacks you can put your js
    Example snippet::

    success: function(value) {
                var respStat = data.status; 
                    var errorStat = data.errorsMessages;
                    if(respStat =="success"){
                        responseMsg.removeClass().addClass('successMessage').html("Your changes have been saved successfully.").fadeOut(4000);
                        }
                    else{
                        responseMsg.removeClass().addClass('errorMessage').html(errorStat[0]).show();
                    }
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jquery validate & ajax.beginform I'm trying to use the jQuery validate plugin
Possible Duplicate: Use of class definitions inside a method in Java Can we have
Possible Duplicate: Show Page Loading Spinner on Ajax Call in jQuery Mobile Is it
Possible Duplicate: How to use Basic Auth and Jquery and Ajax I want to
Possible Duplicate: Is it posible to use ajax respone outside of it? I've created
Possible Duplicate: Can we use any other TAG inside <ul> along with <li>? Or
Possible Duplicate: jQuery: How to stop AJAX function escaping JSON string used to POST
Possible Duplicate: Why use a framework with PHP? To begin with, I just can
Possible Duplicate: jQuery Ajax always returns “undefined”? I'm trying to come up with a
Possible Duplicate: Can you use $_GET variables when including a file in PHP? Is

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.