我编写了一个简单的Jax-Rs应用程序(Restful),并尝试使用Java代码返回jsp
文件。但是,当我运行应用程序时出现错误:
Could not find MessageBodyWriter for response object of type: com.sun.jersey.api.view.Viewable of media type: text/html;charset=UTF-8
我的jsp文件:
<%@ page import="com.trofimovep.models.Book" %>
<%@ page import="com.trofimovep.dao.BooksDao" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<title>Bookshop</title>
</head>
<body>
This is a bookshop!
The books on our site:
<%
BooksDao booksDao = new BooksDao();
ArrayList<Book> books = booksDao.getBooks();
for (Book book : books) {
out.println("<tr>");
out.println("<th>" + book.getName() + "</th>");
out.println("<th>" + book.getAuthor() + "</th>");
}
%>
<button type="submit">Make order</button>
</body>
</html>
和功能:
@Path("/bookshop")
public class Start {
@GET
@Path("/books")
@Produces({MediaType.TEXT_HTML})
public Response Books() {
return Response.ok(new Viewable("/views/mainPage", null)).build();
}
}
我做错了什么?以及如何解决?