Java spring hol a hiba?
public class Category {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
===========================================
@Controller
public class CategoryController {
@RequestMapping(value ="/addCategory", method = RequestMethod.GET)
public String addCategory(){
return "addCategory";
}
@RequestMapping(value ="/addCategory", method = RequestMethod.POST)
public String addNewCategory(@ModelAttribute ("category") Category category, BindingResult result){
System.out.println("cateory: " + category.getName());
return "addCategory";
}
}
======================================================
<form:form method="POST" commandName="category">
<label for="textinput1">
Enter Category Name :
</label>
<form:input path="name"/>
<br/>
<input type="submit" class="btn" value="Enter Name"/>
</form:form>
May 06, 2016 3:36:48 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [fitTrackerServlet] in context with path [/FitnessTracker] threw exception [An exception occurred processing JSP page /WEB-INF/jsp/addCategory.jsp at line 76
73: <label for="textinput1">
74: Enter Category Name :
75: </label>
76: <form:input path="name"/>
77:
78: <br/>
79: <input type="submit" class="btn" value="Enter Name"/>
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute
........................
Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
.................................
na közben rájöttem a GET metódusba is meg kell jelenjen a
model attribútum
@RequestMapping(value ="/addCategory", method = RequestMethod.GET)
public String addCategory(@ModelAttribute("category") Category category){
return "addCategory";
}
Kapcsolódó kérdések:
Minden jog fenntartva © 2025, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!