2014年5月22日星期四

JSP pages take less than the value stored inside ModelAndView ~ ~

Controller code :

@RequestMapping(value="selectDepts2.do")
public ModelAndView findDepts2() {
 List<Dept> depts=deptService.getDpets();
 ModelAndView mav=new ModelAndView("dept");
 mav.addObject("depts", depts.get(0));
 return mav;
}


jsp page is directly through the $ {depts}

are not being given the whole process , but the page displayed is "$ {depts}" string . .
Internet has also not find the answer , seek help heroes look ~ ~ Thanks ~ ~ !
------ Solution ---------------------------------------- ----
first your "depts" on the property controller in a domain object (requt.setattribute ("depts", depts)), then the expression obtained through EL
------ Solution ------------------------------------------ -
spring of MVC is Servlet package , ModelAndView in addObject method should be on request.setAttribute package, so if you want to in the jsp el expression to read the data , you should use $ {requestScope.depts} , corresponding to <% = request.getAttribute ("depts")%>
------ Solution --------------------- -----------------------
you first learn to understand how to use JSTL tags or how to get away with EL expressions .
------ For reference only -------------------------------------- -


This method can be , but is not directly make modelAndView object into the herd right ..?
------ For reference only ------------- --------------------------
although I do not know why, but the code is replaced by the following can be taken up. . .

@RequestMapping(value="selectDepts2.do")
public ModelAndView findDepts2() {
 List<Dept> depts=deptService.getDpets();
 Map model=new HashMap();
 model.put("depts", depts);
 ModelAndView mav=new ModelAndView("dept",model);
 return mav;
}


introduce errors ModelAndView class may not get value. .
correct class : import org.springframework.web.servlet.ModelAndView;
------ For reference only ------------------- --------------------


how mathematics to understand .. ? previously studied the use of servlet and jstl . Also know the value range of different scope is the first time .. but ModelAndView use
------ For reference only ---------------------- -----------------



tried to use $ {requestScope.depts}, web display or "$ {requestScope.depts}" This string ...
------ For reference only ---------------------------------------
your landlord You can try adding the jsp page <% @ page isELIgnored = "false"%> to see

没有评论:

发表评论