I am working with a spring hibernate project. all pages are working fine but from the last day i am battling with a problem.
In one of page, when page first time load data from controller in model. all data is coming fine.
but after a post request to update some details from page in database and redirect to same GET request. Database is giving updated data which i updated before and printing it to java code. every thing is fine on server side.
But when Model coming on client side on jsp. Old data is coming.
Even i put details in model as well in http request.
Both object not overriding.
One more thing, on my local machine, this page is working fine, but on Live server i am getting this problem.
please help. i am facing this problem from last day.
Asked
Active
Viewed 718 times
1

manish gangwar
- 23
- 6
-
http://stackoverflow.com/questions/1529184/jsps-not-displaying-objects-from-model-in-spring – manish gangwar Mar 16 '12 at 08:34
1 Answers
0
I think the problem is that the page requested by GET becomes cached by the Browser or some Server.
You should add some informations about now to cache the http response to the response.
Spring helps you:
<mvc:interceptors>
<bean id="webContentInterceptor"
class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0" />
<property name="useExpiresHeader" value="true" />
<property name="useCacheControlHeader" value="true" />
<property name="useCacheControlNoStore" value="true" />
<property name="alwaysUseFullPath" value="true" />
<property name="cacheMappings">
<props>
<!-- 2678400 seconds = 31 days -->
<prop key="/resources/images/favicon*.ico">2678400</prop>
<prop key="/resources/images/*.png">2678400</prop>
</props>
</property>
</bean>
</mvc:interceptors>
For example this configruation will instruct Spring to prevent caching for every response exept the favicon and png files.

Ralph
- 118,862
- 56
- 287
- 383
-
Hey Ralph...its not working. even i am sending a Random number from Math.random() in model. after server restart, the random generated first time; is coming after all request from the same CONTROLLER only. – manish gangwar Mar 16 '12 at 09:36
-
still i am not able to understand why my tomcat is saving data only for a particular controller. – manish gangwar Mar 16 '12 at 12:02
-
Maybe I understand you wrong: is the client reciving the old data, or is the server reciving the old data (and the db contains the old data)? – Ralph Mar 16 '12 at 12:12
-
only client receiving the old data. for only this page or controller, data is coming same, database is updating. after updating i am redirecting to the GET url which get fresh data from database using select queries and fresh data is print well in java code. but on jsp, new data is not coming – manish gangwar Mar 16 '12 at 13:17
-
@RequestMapping(value="/company/{p_company_id}/campaign/reports/template",method=RequestMethod.GET) public String showUserCampaignReportsTemplateData(@PathVariable String p_company_id, Model p_model, HttpServletRequest p_request, HttpServletResponse p_response) { p_request.setAttribute("reportTemplateRandom", Math.random()); //SELECT FROM DATABASE FRESH DATA System.out.println("p_model.asMap() : : " + p_model.asMap()); return "dynamic/templatePage"; } – manish gangwar Mar 16 '12 at 13:35
-
@RequestMapping(value="/company/{p_company_id}/campaign/reports/template/update",method=RequestMethod.POST) public String updateCampaignTemplate(@PathVariable String p_company_id,Model p_model, HttpServletRequest p_request, HttpServletResponse p_response) throws IOException { //SOME DATABASE CHANGES HERE return "redirect:/company/"+p_company_id+"/campaign/reports/template?campaignId="+l_campaign_id+"&campaignName="+l_campaign_name; } – manish gangwar Mar 16 '12 at 13:35
-
i enclosed my code as above, when i open page by get request; i random number fixed in model. after post request when redirect to get request, a new random number printing in model map. but i getting the old one number. after only restart the tomcat, this number can be changed. please looking this code. and guide me, where i am doing wrong. – manish gangwar Mar 16 '12 at 13:39
-
Get the server invoked after redirect? (Verified on Server side, for example by an log statement) – Ralph Mar 16 '12 at 14:12
-
Hi Ralph.....I verified all the things....new random number is printing on server...but not moving to client. – manish gangwar Mar 17 '12 at 05:58
-