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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:51:14+00:00 2026-05-25T14:51:14+00:00

my controller: public String showWeather(Model model) { model.addAttribute(weather, weatherService.listCities()); return weather; } my weather.jsp

  • 0

my controller:

public String showWeather(Model model) {
    model.addAttribute("weather",  weatherService.listCities()); 
    return "weather";
}

my weather.jsp

<select class="data">
        <c:forEach items="${weather}" var="city">
            <option>${city.name}</option>
        </c:forEach>
</select>

How can I make that everytime I highlight/select something from the dropdown menu, new info would be displayd next to it from database according to the City?

First of all, must I send all data from database to my JSP with controller at first, or can data be transfered from database to JSP meanwhile I highlight/select items on the list(so when I select city “A”, then the query will get all information about city “A” and I can use the info)?

here are my tables:

CITIES(id serial, name varchar(40))
WEATHER(id serial, city_id int, temp int, data date)

So basically I have list of CITIES in my dropdown menu, and when city is selected, then the WEATHER with that city_id will be queried from database in theory.

If the live updating is not possible, how should I do it otherways?

Feel free to ask questions or give suggestions.

  • 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-25T14:51:15+00:00Added an answer on May 25, 2026 at 2:51 pm

    I think you should use AJAX in this case

    use JQUERY on change event whick will send your cityId to SpringMVC controller, as the response your controller should return wheather, and then update your GUI component with this result:

    then main difference is that your controller should return anything but the view. You can do it using @ResponseBody annotation:

    for example this controller will return you temperature as String when you request
    it for city with id=222

    /getTemperature/222

    @RequestMapping(value="/getTemperature/{id}", method=RequestMethod.GET)
        @ResponseBody
        public String getTemparature(@PathVariable("id") Integer id){
            String weather = someDaoObect.getTemperature(id);
                    return weather;
        }
    

    in this case that code behaves exactly like Servlet where you write your result in HttpServletResponse.

    Hope it will help you.

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

Sidebar

Related Questions

My UserController.java @Controller @RequestMapping(/userRegistration) public class UserController{ @RequestMapping(method = RequestMethod.GET) public String showForm(ModelMap model)
i wrote a simple function in controller public string LinkProjectSquareFilter(int squareId) { return squareId.ToString();
Have Controller: public class MyController : Controller { [HttpGet] public ActionResult MyAction(int iMode, string
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
public class HomeController : Controller { public ActionResult Index() { Task<string> t = DownloadStringTaskAsync(new
In my controller: @RequestMapping(value = /, method = RequestMethod.GET) public String index() { return
public class HomeController : Controller { public ActionResult Index() { return View(); } /*
I have cratet simple Model public class ModelTest { public string MyValue { get;
I have this controller: public JsonResult Register(string step , GlobalOnBoardingDataModel data){} the MVC wont
Here is my model: public class Items { public string Foo { get; set;

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.