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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:39:37+00:00 2026-05-25T15:39:37+00:00

I am using spring mvc 3.0 to build an web application. User can get

  • 0

I am using spring mvc 3.0 to build an web application.

User can get customers by writing their id or just sends empty form and i turn back all customers that user can traverse between customers by using buttons. Question is how to do it via ajax or javascript without postbacking.

I add customer object to modelAttribute and in my jsp file using :

 <form:form modelAttribute="Customer" method="POST">
           <form:input path="name"/>

@RequestMapping(value = "/customer", method = RequestMethod.GET)
    public String handleCustomer(Model md,HttpSession session) {

       Customer customer= (Customer ) session.getAttribute("customer");

        if( customer== null)
        {
            customer=  new Customer ();
        }
        md.addAttribute("Customer ",customer);
        return "customer";
    }

Here is the question how to change this model attribute without postback. Now according to this get method when I set Customer object all fields are set since I am using “path” to bind fields. I tried to change via ajax callback but it does not work. I don’t want to get all fields and assign one by one with jQuery.

Here is my JS function:

    $("#Customer").submit(function() {
//                var customer= $(this).serializeObject();
//                $.postJSON("Customer", customer, function(data) {
//                  
//                });

                $.getJSON("customer/query.htm",{ id: $('#id').val() }, function(result) {                           

                    $('#testdiv').val(result);

            });
                return false;               
            });

I have tried both getJSON and postJSON functions. Can you link some sort of book, tutorial or documentation it will be helpful.

  • 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-05-25T15:39:38+00:00Added an answer on May 25, 2026 at 3:39 pm

    Here is the answer of my question i could not find a way to refresh my form with json response.

    But with ajax webrequest.

    Here is the ajax Utils class.

    import org.springframework.web.context.request.WebRequest;
    
    public class AjaxUtils {
    
        public static boolean isAjaxRequest(WebRequest webRequest) {
            String requestedWith = webRequest.getHeader("X-Requested-With");
            return requestedWith != null ? "XMLHttpRequest".equals(requestedWith) : false;
        }
    
        public static boolean isAjaxUploadRequest(WebRequest webRequest) {
            return webRequest.getParameter("ajaxUpload") != null;
        }
    
        private AjaxUtils() {}
    }
    

    in controller we add

     @RequestMapping(value = "/customer.htm", method = RequestMethod.GET)
        public String handleCustomer(Model md, HttpSession session,WebRequest webRequest) {
    
              Customer customer= (  Customer ) session.getAttribute("customer");
    
            if (customer== null) {
                customer= new   Customer();
            }
            md.addAttribute("Customer", customer);
            md.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(webRequest));
            return "customer";
        }
    
        @RequestMapping(value = "/customer.htm", method = RequestMethod.POST)
            public String processSubmit(  Customer  customer, BindingResult result, WebRequest webRequest, HttpSession session, Model model) {
                customer= dataService.getCustomer(customer.getId());
    
                session.setAttribute("customer", customer);
                if (AjaxUtils.isAjaxRequest(webRequest)) {
                    // prepare model for rendering success message in this request
                    model.addAttribute("ajaxRequest", true);
                                model.addAttribute("Customer",customer);
                    return null;
                }
    
    
                return "customer";
            }
    

    functions so in jsp or view side we post page with :

    $("#Customer").submit(function() {  
                        $.post($(this).attr("action"), $(this).serialize(), function(html) {
                            $("#customerdiv").replaceWith(html);
    
                        });
                        return false;  
                    });
    

    To summarize with the help of the ajax utils class we set the type of the request full postback or ajaxrequest in our post handler function we made our changes and this changes directly affects the page and form. No need to handle response or set all fields one by one with jquery hope this helps someone.

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

Sidebar

Related Questions

I am using Spring MVC to build my web application, and I have a
I'm building a MVC web application (using the Spring MVC framework), and I'm a
I use Spring MVC (via Spring Roo) to build a small web application for
I'm trying build my application using REST and Spring MVC. For some entities I
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
I'm trying to write a web application using SpringMVC. Normally I'd just map some
I am using Spring Forms for my web application. For nested properties, the form
Is there a way to build Spring Web calls that consume and produce application/json
I'm using the Spring MVC to build a thin layer on top of a
We are using Hibernate 3.1 with Spring MVC 2.0. Our problem occurs when data

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.