Hi Guys,
I am new to Spring MVC annotations.
Please see the code and let me know what is the issue, if possible.
It's just a simple form. I am trying to display a searchForm and based on that want to display the search results. The form is not getting displayed. When I try to hit the url in debug mode the s
Please find my code below:java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'search' available as request attributehowSearchForm() method is invoked but I am facing
SearchController.java
web.xml
@Controller
@RequestMapping("/search")
@SessionAttributes("search")
public class SearchController {
private ISearchService searchService;
public void setSearchService(ISearchService searchService) {
this.searchService = searchService;
}
@RequestMapping(method=RequestMethod.GET)
public String showSearchForm(Model model){
SearchCriteriaBean criteriaBean = new SearchCriteriaBean();
model.addAttribute("criteriaBean",criteriaBean);
return "searchForm";
}
public String onSubmit(@ModelAttribute("search") SearchCriteriaBean criteriaBean ){
searchService.search(criteriaBean);
return "redirect:searchForm";
}
}
spring-servlet.xml<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
<!-- <init-param>
<param-name>ConfigApplicationContext</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param> -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
</listener>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
.....
<bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver"
pr efix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean id="searchService" class="org.krams.tutorial.service.SearchService"></bean>
<!-- <bean name="/search"
class="org.krams.tutorial.controller.SearchControl ler"
p:searchService-ref="searchService"
p:formView="searchForm"
p:successView="searchForm" /> -->
</beans>
applicationContext.xml
<!-- This required so that Spring can recognize our annotated beans -->
<context:annotation-config />
<!-- This required so that Spring can recognize certain annotations,
For example @Controller and @Service. Make sure you set the correct base-package
-->
<context:component-scan base-package="org.krams.tutorial" />
<!--
This is responsible for automatically converting our custom POJO to JSON.
Make sure you have Jackson in your classpath
-->
<mvc:annotation-driven />
Please suggest me a way to remove this IllegalStateException.


r efix="/WEB-INF/jsp/" p:suffix=".jsp" />
Reply With Quote