2012-11-16 2 views
0

이미 스프링 프레임 워크를 사용하여 시작하고 이미 내가 (그러나 사실 내가 그것을 해결할 수없는) 나는 보이는 컨트롤러가 바보 같은 문제의 어떤 종류 건너 온 같은 :SpringMVC REST 웹 서비스

package org.springframework.rest; 

import java.net.MalformedURLException; 
import java.net.URL; 
import java.util.HashMap; 
import java.util.Map; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.ResponseBody; 


@Controller 
public class SomeController { 

    @RequestMapping(value = "/", method = RequestMethod.GET) 
    @ResponseBody 
    public String returnHtmlPage() { 

     return "page"; 

    } 

} 

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<html> 
<head> 
    <title>Home</title> 
</head> 
<body> 
<h1> 
    Hello world! 
</h1> 

<P> The time on the server is ${serverTime}. </P> 
</body> 
</html> 

하지만 HTML 파일의 insteed 내가에만 문자열 "페이지"반환 페이지 page.jsp입니다. 문제를 어떻게 해결할 수 있습니까?

+4

'@ ResponseBody'를 제거하십시오 :) 그럼 REST 서비스 또는 웹 애플리케이션을 만드시겠습니까? –

+0

나는 그것을 믿을 수 없다! 거의 이것에 썼다! 고마워요, 보리스! 질문에 대해, 지금은 봄 프레임 워크를 발견하고 있습니다.이 후에 REST 서비스를 만들려고합니다. – Mithrand1r

답변

1

귀하의 코드는 @ResponseBody로 인해 "페이지"만 인쇄됩니다. 웹 페이지를 반환하지 않습니다. 메소드 출력으로 "String"대신 "ModelAndView"를 사용할 수 있습니다. 그리고 JSP 페이지 이름 (= page)을 설정하십시오.

@RequestMapping(value = "/", method = RequestMethod.GET) 
public ModelAndView returnHtmlPage(){ 
    ModelAndView model = new ModelAndView("page"); 
       /* here you can put anything in 'model' object that you 
        want to use them in your page.jsp file */ 
    return model; 
}