2014-07-14 4 views
0

안녕 페이지에 Spring MVC을 쓰려고합니다.스프링 EL이 작동하지 않습니다.

Hello.jsp 라

<%@page isELIgnored="false"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
    </head> 
    <body> 
     <h1>${hello.test()}</h1> 
    </body> 
</html> 

컨트롤러 수준 :

package Controllers; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 

@Controller 
public class Hello { 

    @RequestMapping(value="/test.htm") 
    public String test() 
    { 
     return "Hello"; 
    } 

} 

하지만 호출되지 않습니다 test()http://localhost:8080/WebApplication1/test.htm 방법을 요청할 때. 문제가 무엇입니까?

+0

아니면 그냥 아무것도 또는 기대 값없이 본문 내용을 보여주지 :

@Controller public class Hello { @RequestMapping(value="/test.htm") public String test(Model uiModel){ uiModel.addAttribute("yourkey", "Hello World"); // put some data return "Hello"; // means "open Hello.jsp" } } 

지금 당신은 데이터를 읽을 수 있습니까? –

+0

@JorgeCampos 아무런 증언도 없습니다. 빈 페이지가 있지만 _hello_가 될 것으로 예상됩니다. –

+0

EL :'

$ {hello.test()}

나는 바로 뒤에있는이 줄을 Hello.jsp에 추가하십시오!'페이지를 테스트하여 결과를 확인하십시오. –

답변

2

뷰에서 컨트롤러 메서드를 호출하면 안됩니다. 당신은 JSF로 할 수 있지만 JSP로 할 수는 없다. 이 예를 살펴 보겠습니다 : 예외가 있습니까

<%@page isELIgnored="false"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 
    <h1>${yourkey}</h1> 
</body> 
</html> 
+0

호호. 실제로 작동한다. 신난다, 당신은 마법사 다! :) –

관련 문제