How to load the data in index page using spring mvc? -


i tried couple of tutorial in spring-mvc load data in index page without using ajax call means before loading index page want data server , load data index page.but did not proper answer.

finally after couple of try got answer.here code.

web.xml      <display-name>springtest</display-name>   <welcome-file-list>     <welcome-file>index.jsp</welcome-file>   </welcome-file-list>   <servlet>         <servlet-name>spring</servlet-name>         <servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>   <servlet-mapping>     <servlet-name>spring</servlet-name>     <url-pattern>/</url-pattern> </servlet-mapping>  <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>/web-inf/spring-servlet.xml</param-value> </context-param>  <listener>     <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener>   controller      @controller     public class webcontroller {          @autowired         private employeeservice empservice;          @requestmapping(value = "/", method = requestmethod.get)        public modelandview index() {            list<employee> emplist = empservice.getallemployee();            collections.sort(emplist, new employeesortbyid());            modelandview modelmap = new modelandview("index","employeelist", emplist);            system.out.println("calling controller");            return modelmap;        }     }    spring-context.xml   <context:component-scan base-package="com.app.controller,com.app.dao.impl,com.app.service.impl" />    <mvc:annotation-driven/>     <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">         <property name="prefix" value="/web-inf/pages/" />         <property name="suffix" value=".jsp" />     </bean> 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -