2016-03-21 4 views
0

に胸が張り裂けるされていない以下の予想通り、私のJSPページがレンダリングされていないコード春モデルオブジェクトが<code>spring</code><code>mvc</code>プロジェクトを作成しながら、私は問題に直面していますjspページ

私のコントローラは

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
public class HelloController { 

    @RequestMapping("/welcome") 
    public ModelAndView helloWorld(){ 

     ModelAndView model=new ModelAndView("HelloPage"); 
     model.addObject("msg","hello page"); 
     return model; 

    } 


} 

JSPページですです以下

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<h2> {$msg}</h2> 
</body> 
</html> 

出力

です

enter image description here

答えて

3

あなたはほとんどそれを得たが、あなたはここにタイプミスがあります

<h2> {$msg}</h2> 

春は、Bean /モデル属性を参照するために${nameOfAttr}を使用していますので、...あなたが書く必要があります:

<h2> ${msg}</h2> 

あなたのメッセージが期待通りに表示されます。さらに情報についてcheck this link

+0

は私がすべての時間に発生聞いて喜んその愚かな間違い –

+1

を... :)知っている、あなたに感謝し、新鮮な目は通常、偉大な知識 –

+1

笑素敵な引用以上を助けてください –

関連する問題