Я новичок в Spring MVC и не могу понять, почему я продолжаю получать ту же ошибку:
java.lang.IllegalStateException: ни BindingResult, ни обычный
целевой объект для имени компонента "articleName", доступный как запрос
атрибут
Кто-нибудь может помочь?
Заранее спасибо
JSP код:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add article</title>
</head>
<body>
<h1>Add article</h1>
<c:url var="viewArticlesUrl" value="/articles.htm"/>
<a href="${viewArticlesUrl}">Show all Articles</a>
<br/><br/>
<c:url var="saveArticleUrl" value="/articles/save.htm"/>
<from:form modelAttribute="article" method="POST" action="${saveArticleUrl}">
<form:label path="articleName">Article name:</form:label>
<form:input path="articleName"/>
<br />
<form:label path="articleDesc">Article Desc:</form:label>
<form:textarea path="articleDesc" />
<br />
<input type="submit" value="Save Article" />
</from:form>
</body>
Контроллер:
@Controller
@RequestMapping("/articles")
public class ArticleController {
@Autowired
private ArticleService articleService;
@RequestMapping(value="/save", method=RequestMethod.POST)
public ModelAndView saveArticle(@ModelAttribute("article")Article article, BindingResult result){
articleService.addArticle(article);
return new ModelAndView("redirect:/articles.html");
}
@RequestMapping(method=RequestMethod.GET)
public ModelAndView listArticles(){
Map<String, Object> model=new HashMap<String, Object>();
model.put("articles", articleService.listArticles());
return new ModelAndView("articlesList", model);
}
@RequestMapping(value="/add", method=RequestMethod.GET)
public ModelAndView addArticle(@ModelAttribute("article") Article article, BindingResult result){
return new ModelAndView("addArticle");
}
}
грузоотправитель:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
<prop key="articles.htm">articleController</prop>
<prop key="articles/add.htm">articleController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<!-- article controller -->
<bean name="articleController" class="controller.ArticleController"/>
@Entity
@Table(name="article")
public class Article {
@Id
@GeneratedValue
@Column(name="article_id")
private Long articleId;
@Column(name="article_name", nullable=false, length=20)
private String articleName;
@Column(name="article_desc", nullable=false)
private String articleDesc;
@Column(name="date_added")
@Temporal(javax.persistence.TemporalType.DATE)
private Date addedDate;
public Article() {
}
public Long getArticleId() {
return articleId;
}
public void setArticleId(Long articleId) {
this.articleId = articleId;
}
public String getArticleName() {
return articleName;
}
public void setArticleName(String articleName) {
this.articleName = articleName;
}
public String getArticleDesc() {
return articleDesc;
}
public void setArticleDesc(String articleDesc) {
this.articleDesc = articleDesc;
}
public Date getAddedDate() {
return addedDate;
}
public void setAddedDate(Date addedDate) {
this.addedDate = addedDate;
}
}
У меня проблема: когда я делаю запрос GET