2015-10-08 73 views
0

顯示數據這是我的控制器代碼Spring MVC的:JSP文件不從控制器

@RequestMapping(value="/testMvc") 
     public String testero(Model model){ 
         String nameClient="HENOCKE"; 
        Long CodeClient=2L; 
        String Address="LONDO Street"; 

     System.out.println("****End and outputting to Jsp page: ****"); 
     return "rs"; 

     } 

正如你可以看到我想要的數據顯示,以我的jsp文件,這是我的JSP文件:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@taglib uri="http://www.springframework.org/tags/form" prefix="f"%> 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" charset=UTF-8> 
<title>Banque </title> 
<link rel="stylesheet" type="text/css" 
    href="<%=request.getContextPath()%>/resources/CSS/style1.css"> 

</head> 
<body> 
    <h2>Date Loaded from My controller....</h2> 

    <table> 
    <tr> 
    <th>Name : </th> <th><c:out value="${nameClient}"/></th> 
    </tr> 

    <tr> 
    <th>id Client: </th> <th> <c:out value=" ${CodeClient}" /> </th> 
    </tr> 
    <tr> 
    <th>Adress client: </th> <th> <c:out value="${Address}" /></th> 
    </tr> 

    </table> 
</body> 
</html> 

如何輸出數據到我的jsp?這裏rs是我的Jsp文件的名稱

回答

0

您應該創建ModelAndView對象放在值的觀點:

@RequestMapping(value="/testMvc") 
    public ModelAndView testero(){ 
     ModelAndView mov = new ModelAndView("rs"); 

     mov.addAttribute("nameClient", "HENOCKE"); 
     mov.addAttribute("CodeClient", 2L); 
     mov.addAttribute("Address", "LONDO Street"); 

     System.out.println("****End and outputting to Jsp page: ****"); 
     return mov; 
    } 
相關問題