Reputation: 2295
Here is my controller:
@RequestMapping("/com/index.do")
public String index(ModelMap model) throws Exception {
MyClass obj=new MyClass();
model.addAttribute("obj",obj);
return "/com/index";
}
Here is my view:
<%@page contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%@page import="org.springframework.ui.ModelMap" %>
<%
ModelMap model=new ModelMap();
Object obj=model.get("obj");
%>
In here obj is null. In this case, how to retrieve that obj in view?
Note: I need to use in jsp tag (<% %>), not like this:
${obj}
Thanks!
Upvotes: 1
Views: 5592
Reputation: 23
you must import jstl lib in jsp page
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Upvotes: 1
Reputation: 1866
You need to access using the Expression Language in JSP like ${obj}. For example if you want to print that in your jsp in an input text
(assuming your MyClass is having getName and setName or you can change whatever getter setter you have in that class)
If you using spring tld's then you check out spring:form tags to set the path so that your bean and the html elements can be binded.
Check this out http://forum.springsource.org/showthread.php?73583-Accessing-model-attributes-in-JSP
Upvotes: 2