【发布时间】:2011-06-14 16:53:54
【问题描述】:
我有一个 Spring MVC 控制器类(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();
}
}
当我转到 index.jsp 时,如何知道 @RequestMapping("/index.jsp") 触发良好?因为我不知道我是否为@RequestMapping 注释设置了正确的值,或者@ModelAttribute 可能有问题,因为它也不会触发..
在我的 index.jsp 中有这样的代码:
<p>
<span>from SampleService: ${textFromService} </span>
</p>
关于我的使用/设置:
我在 web.xml 中有 DispatcherServlet,我有,但它不起作用。我猜 ModelAndView 这是使用 MVC 的旧方法,@ModelAttribute 这是我理解的新方法。所以这就是我使用@ModelAtrribute 的原因。
我在构造函数的 EJBCaller 的 jbossConsole 中有输出,但在 call() 方法调用时没有输出,这就是为什么我不知道这个方法是否运行。
【问题讨论】:
标签: java spring-mvc