2014-04-02 25 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