How do I access ModelMap in a jsp?

James :

How can an object be accessed from the ModelMap in jsp so that a method can be called on it? Currently I recieve this error:

Syntax error on token "$", delete this token

JSP

<body>
        <% MenuWriter m = ${data.menus} %>
        <%= m.getMenus()%>  
</body>

Java

@Controller
@RequestMapping("/dashboard.htm")
@SessionAttributes("data")
public class DashBoardController {

    @RequestMapping(method = RequestMethod.GET)
    public String getPage(ModelMap model) {
        String[] menus = { "user", "auth", "menu items", };
        String[] files = { "menu", "item", "files", };
        MenuWriter m = new MenuWriter(menus, files);
        model.addAttribute("menus", m);

        String[] atocs = { "array", "of", "String" };
        model.addAttribute("user_atocs", atocs);

        return "dashboard"; 
    }
}
skaffman :

The <% %> syntax is deprecated, and shouldn't be used any more.

The equivalent in modern JSP of your JSP fragment would be:

<body>
   ${menus.menus}
</body>

Obviously, that looks confusing, so you may want to consider renaming parts of your model for clarity.

Also, your annotation

@SessionAttributes("data")

does nothing here, since you have no entry in the ModelMap with the key data. This is only useful if you want to keep the model data across the session, which it doesn't seem you need to here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I dynamically access request parameters with JSP EL?

Spring: JSP not reading passed ModelMap?

Why ModelMap, Model, @ModelAttribute, ModelAndView required when a simple return of jsp page name in string can do the work

how do I display the image in jsp

How do i solve this code in JSP?

How do I access phpmyadmin?

How do I access getToken in

How do I access these JSONObjects?

How do I do "nested if" in JSTL for Java JSP?

How do I access the textfile I created?

How do i return a jsp as a response from this servlet?

Custom JSP tag - How do I get the body of the tag?

How do I pass information from a servlet to a JSP page

How do I load css files for different locales in jsp?

How do I check if variable exists in a jsp page for post in index?

How do I get an object from Model to AngularJS variable in JSP?

How do I create a Hierarchical Pie chart in html and servlet or jsp?

How do I pass JavaScript values to Scriptlet in JSP?

How do I open a jsp page as a popup via a spring controller?

How do I use JavaScript's sessionstorage with JSP?

How do i call C++ function from a JSP

How do I import servlet class in jsp when package is default?

How do i pass an object from jsp to controller with spring

How do I redirect from ajax post to servlet to jsp?

How do I upload JSP file content to textarea

Hide JSP page from direct access, but how do you access to the target page?

How do I access anchor tag in JavaScript?

How do I access environment variables in Python?

How do I access a shapefile using gdal?