我在这个社区很新,并提出了我的第一个问题。
我使用 JSP,我成功创建了 JSP 站点,这些站点使用 jsp:setParameter 和 jsp:getParameter 和单个字符串。
现在我想对整个对象做同样的事情(是的,我知道字符串也是一个对象:P)。我尝试了以下方法:
这是我的豆:
@Entity
@Table(name="TBL_SPJ_MOVIE")
public class Movie implements Serializable {
@Id
@Column(name="MOVIE_ID", unique=true)
private int movieID = 0;
@Column(name="MOVIE_BACKDROPPATH")
private String backDropPath = "";
@Column(name="MOVIE_ORIGINALTITLE")
private String originalTitle = "";
@Column(name="MOVIE_POPULARITY")
private double popularity = 0.0;
@Column(name="MOVIE_POSTERPATH", length=1000)
private String posterPath = "";
@Temporal(TemporalType.DATE)
@Column(name="MOVIE_RELEASEDATE")
private Date releaseDate = null;
@Column(name="MOVIE_TITLE")
private String title = "";
@Column(name="MOVIE_ADULT")
private boolean adult = false;
@Column(name="MOVIE_BUDGET")
private int budget = 0;
@Column(name="MOVIE_HOMEPAGE", length=1000)
private String homepage = "";
@Lob
@Column(name="MOVIE_OVERVIEW", length=1000)
private String overview = "";
@Column(name="MOVIE_RUNTIME")
private int runtime = 0;
@Column(name="MOVIE_VOTEAVERAGE")
private double voteAverage = 0.0;
@Column(name="MOVIE_VOTECOUNT")
private int voteCount = 0;
public Movie() {}
//##########################################################################################
@SuppressWarnings("unchecked")
@Transient
public List<Movie> getMovies() {
List<Movie> movies = new ArrayList<Movie>();
EntityManagerFactory factory = Persistence.createEntityManagerFactory("SPJUnit");
EntityManager em = factory.createEntityManager();
Query query = em.createQuery("SELECT m FROM Movie m");
movies = (List<Movie>)query.getResultList();
return movies;
}
@Transient
private Movie currentMovie = null;
public Movie getCurrentMovie() {
return currentMovie;
}
public void setCurrentMovie(Movie currentMovie) {
this.currentMovie = currentMovie;
}
//##########################################################################################
// Getter and Setter
public String toString() {
return title;
}
}
这是我的电影.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:useBean id="movie" class="de.Movie"></jsp:useBean>
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<link href="../css/movies.css" type="text/css" rel="stylesheet">
<title>Movie Titles</title>
</head>
<body>
<div id="wrapper">
<br></br>
<h2 id="title">Movie Titles</h2>
<br></br>
<ul>
<c:forEach var="movie" items="${movie.movies}">
<li id="listElement">
<form action="../pages/singleMovie.jsp">
<input type="submit"
name="currentMovie"
value="${movie}"
/>
</form>
</li>
</c:forEach>
</ul>
</div>
</body>
</html>
在这里,我有一个所有电影的大清单。我认为由于我的 toString() 方法,所有标题都被打印出来了,对吗?有了这些表格,我想将选定的电影提交给另一个 jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:useBean id="movie" class="de.Movie"></jsp:useBean>
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<link href="../css/singleMovie.css" type="text/css" rel="stylesheet">
<title>Movie</title>
</head>
<body>
<div id="wrapper">
<jsp:setProperty name="movie" property="*" />
<br></br>
<h2 id="title"><jsp:getProperty name="movie" property="currentMovie" /></h2>
<br></br>
</div>
</body>
</html>
似乎只发送了电影的标题,因为当我调用 singleMovie.jsp 时出现以下错误:
org.apache.jasper.JasperException: org.apache.jasper.JasperException: org.apache.jasper.JasperException: PWC6338: Cannot convert "Ariel" for the attribute currentMovie of the bean de.Movie: PWC6348: Property editor not registered with the PropertyEditorManager
“Ariel”是我选择提交的电影的标题。
我想发送整个电影,这样我就可以在我的 singleMovie.jsp 中使用 Movie-Bean 的所有字段。
只要我只是使用电影的标题,一切都很好。
那我做错了什么?