English 中文(简体)
Spring Hibernate, Update JSP view while selected fromdown menu
原标题:Spring Hibernate, updating JSP view while selecting from dropdown menu

我的控制者:

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

我的天气。 jsp

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

我怎么能够表明,每当我强调/选择从下降的菜单中选取的东西时,将根据<<>City从数据库中显示新的信息。

首先,我必须首先从数据库中把所有数据寄给我的控制员联合调查组,或者从数据库转到联合调查组的数据,同时,我强调/选择列入清单的项目(当我选择城市“A”时,询问会获得有关城市“A”的所有信息,我可以利用信息)?

我的表格如下:

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

因此,在我下台的菜单中,我基本上有<代码>CITIES,在选择城市时,从理论上从数据库中查询WEATHER

如果不可能进行现场更新,我应如何利用其他途径?

自愿提出问题或提出建议。

最佳回答

我认为,你在此案中应当使用美国航天局。

利用J RequestRY on change event tempck, 寄送贵城市 Id to SpringMVC controller, as the response You controller should 回去小麦, 然后更新你的全球调查部分,结果:

那么,主要区别是,你的控制者应当回去任何东西,但这一观点除外。 您可使用<代码>@ResponseBody说明:

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;
    }

在此情况下,如果你在<代码>上写明你的成果,则该代码与Serlet一样。 HttpServletResponse。

希望能帮助你们。

问题回答

你谈论的正是Ajax方案的重点(见Ajax Program),在服务器和客户(浏览器)之间提供数据,按时间顺序发送和检索数据。 在您的情况下,当用户选择和逐项申请时,必须去向服务器询问需要做些什么(db的最新信息,将一些东西退回浏览器等)。

就你而言,我不知道你能否包括一个新的图书馆并使用该图书馆,但是在 Java的一个网络项目中有很多人可以使用,因此很容易整合和使用:

也可以包括美丽的贾瓦文图书馆之一(前文: j、普罗托型、Ext、Et)。 Dojo等)提供同样的功能,在浏览器和服务器之间发送和接收信息。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签