2013-01-24 26 views
0

你好我下面Passing parameters from JSP to Controller in Spring MVC显然我失去了一些东西,因为我越来越结合的形式在春对象3.0

javax.el.PropertyNotFoundException:房产“标题”不是类型com.outbottle.hellospring发现.entities.Movie

任何想法,我失踪了?

我的控制器:

package com.outbottle.hellospring.controllers; 

import com.outbottle.hellospring.entities.Movie; 
import java.util.Map; 
import javax.servlet.http.HttpServletRequest; 
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 org.springframework.web.bind.annotation.SessionAttributes; 



@Controller 
@SessionAttributes("Movie") 

public class FormPractice{ 

//display the form 
@RequestMapping(value="/form", method= RequestMethod.GET) 
public String form(ModelMap map) { 

    map.addAttribute("Movie", new Movie()); 
    //return new ModelAndView("form", "movie", new Movie()); 
    return "form"; 

} 


// Process the form 

@RequestMapping(value="/showMovies", method = RequestMethod.POST) 
public String processMovieRegistration(@ModelAttribute("Movie") Movie moviedata, 
             BindingResult result,           
             HttpServletRequest request, 
             Map<String, Object> map){ 


    //System.out.print(moviedata.Title); 
    map.put("moviedata", moviedata); 
    //map.addAttribute("movie", moviedata); 

    map.put("date", request.getParameter("date")); 

    return "showMovies"; 
} 



    public Movie formBackingObject() { 
    return new Movie(); 
    } 

} 

我的对象

package com.outbottle.hellospring.entities; 

import java.util.Date; 




public class Movie { 

    private String Title; 
    private Date ReleaseDate; 



    /** 
    * @return the ReleaseDate 
    */ 
    public Date getReleaseDate() { 
     return ReleaseDate; 
    } 

    /** 
    * @param ReleaseDate the ReleaseDate to set 
    */ 
    public void setReleaseDate(Date ReleaseDate) { 
     this.ReleaseDate = ReleaseDate; 
    } 

    /** 
    * @return the Title 
    */ 
    public String getTitle() { 
     return Title; 
    } 

    /** 
    * @param Title the Title to set 
    */ 
    public void setTitle(String Title) { 
     this.Title = Title; 
    } 


} 

形式

<form:form method="post" action="showMovies" modelAttribute="Movie" commandName="Movie"> 

    <table> 
     <tr> 
      <td>Title</td> 
      <td><form:input path="Title" /></td> 
     </tr> 
     <tr> 
      <td>Date</td> 
      <!--Notice, this is normal html tag, will not be bound to an object --> 
      <td><input name="date" type="text"/></td> 
     </tr> 
     <tr> 
      <td colspan="2"> 
       <input type="submit" value="send"/> 
      </td> 
     </tr> 
    </table> 

</form:form> 

的观点:

<body> 
    <h3>Here are the list</h3> 

    <c:choose> 
     <c:when test="${not empty moviedata.Title}"> 
      <b>${moviedata.Title}</b> 
     </c:when> 
     <c:otherwise> 
      <b>No Movie yet.</b> 
     </c:otherwise> 
    </c:choose> 
<br /> 
<br /> 
    <c:choose> 
     <c:when test="${not empty date}"> 
      <b>${date}</b> 
     </c:when> 
     <c:otherwise> 
      <b>still nothing.</b> 
     </c:otherwise> 
    </c:choose> 
</body> 
+0

也许你没有编译过类并重新部署到你的应用服务器中? JSP可以在不重新部署的情况下更改,但必须重新部署Java类 – gerrytan

+0

已经做到了。但我仍然收到错误。 =( – rax313

+0

嗯..尽量遵循JavaBeans约定可能?不是的大写“标题”,尝试小写的“冠军”。Java的编译EL $ {} aa.bb到aa.getBb() – gerrytan

回答

1

不知道为什么,但在标题去掉大写字母“T”的工作..

<body> 
<h3>Here are the list</h3> 

<c:choose> 
    <c:when test="${not empty moviedata.title}"> 
     <b>${moviedata.title}</b> 
    </c:when> 
    <c:otherwise> 
     <b>No Movie yet.</b> 
    </c:otherwise> 
</c:choose> 

如果任何人都可以解释为什么这工作,这将有助于我理解SPRING 3.0快..但现在我只是很高兴我能继续前进。

+2

在http://docs.oracle.com/javaee/6/tutorial/doc/bnahu.html – gerrytan

+0

有一个读感谢你有一个给予好评=) – rax313