1

I can't get the model by using jstl

Controller.java

@RequestMapping(value="/update/{url_mapping}",method = RequestMethod.GET)
public ModelAndView updatePicture(@PathVariable String url_mapping) {
    Picture picture = new Picture();
    String url = url_mapping+".jpg";
    ModelAndView modelAndView =  new ModelAndView();

    picture = (Picture) pictureInfo.findPicture(Picture.class, url);
    modelAndView.addObject("picture", picture);
    modelAndView.setViewName("redirect:/update.jsp");

    return modelAndView;
}

I've tried that it can fetch the data from db, but when I use modelandview to pass model and view to update.jsp, it didn't show any thing.

update.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <c:out value="${picture.url_mapping}"/>
</body>
</html>
AnthonyLu
  • 23
  • 5
  • Why you used redirect ?? just use `ModelAndView modelAndView = new ModelAndView("update.jsp");` and remove the line `modelAndView.setViewName("redirect:/update.jsp");`. – Ataur Rahman Munna Nov 14 '17 at 09:51

0 Answers0