Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
Spring
Not able to read value of map attribute in jsp
somashaker goud
Ranch Hand
Posts: 64
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
below is my controller class
package com.howtodoinjava.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.howtodoinjava.entity.VegetableEntity; import com.howtodoinjava.service.VegetableManager; @Controller public class EditVegetableController { @Autowired private VegetableManager vegetableManager; public void setVegetableManager(VegetableManager vegetableManager) { this.vegetableManager = vegetableManager; } @RequestMapping(value = "/addveghome", method = RequestMethod.GET) public String listVegetables(ModelMap map) { map.addAttribute("veg", new VegetableEntity()); map.addAttribute("Added","Added Successfully"); return "vegetables"; } @RequestMapping(value = "/addveg", method = RequestMethod.POST) public String addVegetables(@ModelAttribute(value = "veg") VegetableEntity veg, BindingResult result) { vegetableManager.addVegetable(veg); return "redirect:/addveghome"; } }
jsp
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!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=ISO-8859-1"> <title>Add vegetables</title> </head> <body> <form:form method="post" action="addveg" commandName="veg"> <table> <tr> <td>Name:</td> <td><form:input path="name"/></td> </tr> <tr> <td>Breed :</td> <td><form:input path="breed"/></td> </tr> <tr> <td>Amount :</td> <td><form:input path="amount"/></td> </tr> <tr> <td colspan="2"> <input type="submit" value="<spring:message code="label.addveg" />"/> </td> </tr> </table> </form:form> <h1>{Added}</h1> </body> </html>
IN controller for Added variable I am assinging value as
Added successfully
but while trying to display in jsp its getting displayed as
{Added}
let me know where I am missing
Tim Nachreiner
Ranch Hand
Posts: 93
1
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Just guessing, but I think it's because you used:
value={Added}
instead of
value="{Added}"
somashaker goud
Ranch Hand
Posts: 64
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Tim, I tried that too but it didn't worked
Tim Nachreiner
Ranch Hand
Posts: 93
1
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
how about
value="${Added}"
somashaker goud
Ranch Hand
Posts: 64
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yup, it worked. Thanks
Tim Nachreiner
Ranch Hand
Posts: 93
1
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
On another note, because you are using field injection:
@Autowired private VegetableManager vegetableManager;
You can get rid of this line:
public void setVegetableManager(VegetableManager vegetableManager) { this.vegetableManager = vegetableManager; }
somashaker goud
Ranch Hand
Posts: 64
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks good catch
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Neither BindingResult nor plain target object for bean name in SPRING
getting error with Spring tags
controller is not mapping properly
No mapping found for HTTP request
More...