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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:54:39+00:00 2026-06-01T21:54:39+00:00

Basically, I’ve currently got an MVC project I’m working on where I can pass

  • 0

Basically, I’ve currently got an MVC project I’m working on where I can pass values from the server to the client using the following class…

package org.assessme.com;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class UserManagementController {

private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    /**
     * Simply selects the home view to render by returning its name.
     */
    @RequestMapping(value = "/userManagement", method = RequestMethod.GET)
    public Object home(Locale locale, Model model) {
        logger.info("User management view controller loaded...");

        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

        String formattedDate = dateFormat.format(date);

        model.addAttribute("serverTime", formattedDate );
        return "userManagement";
    }
}

This can then be accessed using the notation…

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
    <title>Home</title>
</head>
<body>
<h1>
    Hello world!  
</h1>

<P>  The time on the server is ${serverTime}. </P>
</body>
</html>

My question is, how would I change this project so that I could use JSON as the Ajax requests so say a user clicks a button that has…

function userManage(){
    $('div.mainBody').load('userManagement');
}

I want userManagement to return the view userManagement (like it does now), but also a json response of users.

Can anyone give me any advice around this?

Thanks,

  • 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-01T21:54:41+00:00Added an answer on June 1, 2026 at 9:54 pm

    In this post, the author explains how you can achieve this using Spring.

    In your controller, you should have something like the below to return a JSON.

    @RequestMapping(value="/availability", method=RequestMethod.GET)
    public @ResponseBody AvailabilityStatus getAvailability(@RequestParam String name) {
        for (Account a : accounts.values()) {
            if (a.getName().equals(name)) {
                return AvailabilityStatus.notAvailable(name);
            }
        }
        return AvailabilityStatus.available();
    }
    

    In your view, you should write a request using JQuery.

    $(document).ready(function() {
        // check name availability on focus lost
        $('#name').blur(function() {
            checkAvailability();
        });
    });
    
    function checkAvailability() {
        $.getJSON("account/availability", { name: $('#name').val() }, function(availability) {
            if (availability.available) {
                fieldValidated("name", { valid : true });
            } else {
                fieldValidated("name", { valid : false,
                    message : $('#name').val() + " is not available, try " + availability.suggestions });
            }
        });
    }
    

    EDIT: You should also check this answear. If you add Jackson jars to your libs, Spring will start to parse your POJOS to JSON.

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

Sidebar

Related Questions

Basically I need to create a client and server using only the local network,
Basically I want to go from -1 to 1 in n steps, including -1
Basically, I have the following code: public class MyDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
Basically what i want to say is can we decide among the list of
Basically, I'm working on a spam detection system and I would like to detect
Basically my rewrite rules work fine but if I am working with files or
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically my sign up form is not working. When I sign someone up it
Basically I have a JFrame for a simple text editor. The filename you're working

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.