Reputation: 91
I am new to Spring mvc, maven and tomcat. I have written a controller for which I have defined a bean. Now when I type the url in broswer like: localhost:8080/hello.htm my controller is called and it is called again when I hit this URL. Eg
<bean name="/hello.htm" class="com.paytm.controller.InventoryController">
<property name="jdbcProductDao">
<bean class="com.paytm.repository.JdbcProductDao">
<constructor-arg ref="dataSource"></constructor-arg>
</bean>
</property>
</bean>
And in the controller
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Product product = new Product();
product.setPrice(23.45);
product.setDescription("Test Product");
this.jdbcProductDao.saveProduct(product);
...
}
As a result the product is saved twice in the DB. My query is why is the controller called when I type the URL(and not hit it)?
Upvotes: 0
Views: 73
Reputation: 12572
Your browser caches your url when it sees
the same url in the omnibox every now and then. Clear your cache and it will fix your issue. You can check your chrome prerenders
by typing this in your chrome browser.
chrome://net-internals/#prerender
For more details your can take a look at this source
Upvotes: 1