I have a Spring MVC Controller class (bean):
@Controller
@RequestMapping("/index.jsp")
public class EjbCaller {
@Autowired
private InfoBean infoBean;
public EjbCaller() {
System.out.println("creating !!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@ModelAttribute("textFromService")
public String call() {
System.out.println("!!!!!!!!!!!!!!!!!!!1 gogogogog");
return infoBean.getRefSampleService().doService();
}
}
How to know that @RequestMapping(“/index.jsp”) fires well when I go to the index.jsp? Because i do not know if I’m putting right value to the @RequestMapping annotation, or maybe something wrong with @ModelAttribute because it does not fire as well..
In my index.jsp i have code like this:
<p>
<span>from SampleService: ${textFromService} </span>
</p>
About my usage/settgins:
I have DispatcherServlet in web.xml, i have , bit it does not work. I guess ModelAndView this is old approach to use MVC, @ModelAttribute this is a new approach as i understand. So that’s why i use @ModelAtrribute.
I have output in the jbossConsole from EJBCaller from constructor but not when call()-method is calling that’s why i do not know if this method runs or not.
Controllers are just one part of the MVC equation, you should have:
Controllers with @RequestMapping annotations noting which URLs they handle, they (essentially) return views. In Spring MVC, these are done with ViewResolvers, the simplest is:
So then you can do something like
In your Spring config file, there are a bunch of options, I often do:
This will then get picked up.
Don’t forget your org.springframework.web.servlet.DispatcherServlet in web.xml