2014-04-02 23 views
2

我想从我的控制器发送jsp数据并试图用Spring EL读取它,但我无法做到这一点。无法读取jsp上的控制器发送的数据

控制器:

@RequestMapping("/home") 
    public String StudentHome(RedirectAttributes ra){ 
     String msg="mydata"; 
     ra.addFlashAttribute("msg", msg); 
     return "home"; 
} 

的jsp:

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
    ${msg} 
</body> 
</html> 

我是否需要包括什么吗?

+0

您是否已将类@Controller注释添加到类中? – StanislavL

+0

是的,我有@Controller注释类 – Dramorian

回答

1

RedirectAttribute当您重定向时才使用。尝试使用return "redirect:home"; -BCP

0
  1. 添加@Controller注解@RequestMapping注释

  2. 以上让您在controller-spring-beans.xml控制器的bean。

样品

<bean name="yourController" 

    class="your.package"> 

    <property name="successView" value="path/to/your.jsp" /> 

</bean> 

阅读Springhere

+0

我有类的@Controller注释。 – Dramorian

+0

您是否添加了像我包含的bean? –

+0

不,我没有。如果我使用注释,那么创建bean有什么用处。你可不可以告诉我abt it bcoz我不知道。 – Dramorian