스프링 model.addAttribute("serverTime", formattedDate) 를 스크립트릿에서 사용하려면 어떻게 해야 할까요?

1,022 views
Skip to first unread message

JH

unread,
Sep 17, 2013, 8:12:53 PM9/17/13
to ks...@googlegroups.com



@RequestMapping(value = "/", method = RequestMethod.GET)
public String homePage(Locale locale, Model model) {
logger.info("home {}", locale);

Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

String formattedDate = dateFormat.format(date);

model.addAttribute("serverTime", formattedDate);
return "/home";
}

컨트롤 단에서 
model.addAttribute 로 serverTime를 설정하고 
이를 jsp에서 

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

이런식으로 사용은 아주 깔끔하고 좋습니다

하지만 저 serverTime 라는 모델 어트리뷰트를
jsp페이지의
<% %> 스크립트 릿 안에다 사용해보고 싶은데

어찌해야 할지를 모르겠네요...
제가 책에서 놓쳤을수도 있지만

스크립트릿 안에다가 
<%= ${serverTime } %>
<%= serverTime  %>

모 이런것들도 아닌거 같아서요
컨트롤 모델에 설정한 값을 스크립트릿 안에서 사용하는 법을 알고 싶습니다

JH

unread,
Sep 17, 2013, 8:33:48 PM9/17/13
to ks...@googlegroups.com

<%=
request.getAttribute("serverTime")
%>
이러면 되는군요 

YongHyuk Lee

unread,
Sep 18, 2013, 4:06:14 AM9/18/13
to ks...@googlegroups.com
request.getAttribute("...")

나의 iPhone에서 보냄

2013. 9. 18. 9:12 JH <kimj...@gmail.com> 작성:

--
Google 그룹스 'Korea Spring User Group' 그룹에 가입했으므로 본 메일이 전송되었습니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 ksug+uns...@googlegroups.com에 이메일을 보내세요.
http://groups.google.com/group/ksug에서 그룹을 방문하세요.
더 많은 옵션을 보려면 https://groups.google.com/groups/opt_out을(를) 방문하세요.
Reply all
Reply to author
Forward
0 new messages