我正在使用 SpringMVC3.2 和 JSP,并且正在尝试显示用户信息。但是我在 JSP 页面上显示它有问题。
这是我的控制器和 JSP 页面:
@Controller
@RequestMapping("/map")
public class EventDataController {
private Logger log = LoggerFactory.getLogger(EventDataController.class);
@Autowired EventDataService eventDataService;
@Autowired UserService userService;
@RequestMapping(method = RequestMethod.GET)
public ModelAndView index() {
ModelAndView mv = new ModelAndView("devicemap");
UserDetails sessionUser = SecurityUtils.currentUserDetails();
User user = userService.findUser(sessionUser.getUsername());
log.info("user==>" + user);
if (user==null){
mv.addObject("error", "Cannot find user.");
} else {
mv.addObject("user", user);
}
return mv;
}
}
devicemap.JSP
<span class="alert" id="userInfo">
<c:choose>
<c:when test="${!empty user}">
${user.userId}
</c:when>
<c:otherwise>
User not found
</c:otherwise>
</c:choose>
</span>
applicationContext.xml
<!-- ViewResolver for JSP -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
当我检查控制器中的用户对象时,它有用户数据并且 devicemap.jsp 在 WEB-INF/pages 中。
我做错了什么?任何帮助,将不胜感激。