Click here to Skip to main content
15,909,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Spring framework.
Here is my controller:
Java
@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:
HTML
<%@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:
HTML
${obj}

Thanks!
Posted
Updated 13-Mar-12 22:00pm
v2

1 solution

You need your controller method to specify the "view" itself. So the return value should be a String that corresponds to the view name for aaaa.jsp. You can then add the map to the model and it will be available in the JSP. Here is the sample code:

C#
@RequestMapping(value = "/forgotPWD",params="username", method = RequestMethod.POST)
public String forgotPassword(@RequestParam(value = "username", required = false) String username,
         Map<String, Object> map, Model model) {
    [snip]
    map.put("forgotUser","Mail has been sent to your mail address");
    model.addAttribute("userMap", map);
    [snip]
    return "message.jsp"; // or just "message" depending on Spring settings
}
 
Share this answer
 
Comments
Bun Leap_kh 13-Mar-12 21:39pm    
Here is just controller!
I need code in view to retrieve userMap!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900