英文:
Problem with displaying List by jsp in Java
问题
<!DOCTYPE html>
<html>
<head>
<title>博客网站-帖子</title>
</head>
<body>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>描述</th>
<th>日期</th>
<th>已完成</th>
<th>作者</th>
</tr>
</thead>
<tbody>
<c:forEach items="${posts}" var="post">
<tr>
<td>${post.postId}</td>
<td><fmt:formatDate pattern="dd/MM/yyyy"
value="${post.postDate}" /></td>
<td>${post.text}</td>
<td>${post.authorId}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</body>
</html>
@Controller
public class PostController {
@Autowired
PostService postService;
@RequestMapping(value="/posts",method = RequestMethod.GET)
public String showPosts(ModelMap model) {
model.addAttribute("posts",postService.findall());
return "posts";
}
}
public class Post {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int postId;
//@Column(unique=true)
//@NotEmpty
private String title;
//@Column(length=20000)
@Size(max=20000, message="消息不能超过20000个字符!")
//@NotEmpty
private String text;
private Date postDate;
private int authorId;
}
希望在 JSP 中显示帖子列表,以查看其工作原理,但显示效果如图所示。是否有 JSP 或控制器的问题?
英文:
Hi i have a problem with my project,That's my posts.jsp
<!DOCTYPE html>
<html>
<head>
<title>Blog Site-posts</title>
</head>
<body>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Date</th>
<th>Completed</th>
<th>Written by</th>
</tr>
</thead>
<tbody>
<c:forEach items="${posts}" var="Post">
<tr>
<td>${Post.postId}</td>
<td><fmt:formatDate pattern="dd/MM/yyyy"
value="${post.postDate}" /></td>
<td>${Post.text}</td>
<td>${Post.authorId}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</body>
</html>
That's my PostController
@Controller
public class PostController {
@Autowired
PostService postService;
@RequestMapping(value="/posts",method = RequestMethod.GET)
public String showPosts(ModelMap model) {
model.addAttribute("posts",postService.findall());
return "posts";
}
}
and that is my post class
public class Post {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int postId;
//@Column(unique=true)
//@NotEmpty
private String title;
//@Column(length=20000)
@Size(max=20000, message="Message cannot be longer than 20000 characters!")
//@NotEmpty
private String text;
private Date postDate;
private int authorId;
I want to display elements of List with posts in jsp to see how it works , but it looks like this :
What's wrong with jsp or controller?
答案1
得分: 0
将以下内容添加到 posts.jsp
文件的 html
标签之前:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
英文:
Add this to posts.jsp
before tag html
:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
专注分享java语言的经验与见解,让所有开发者获益!
评论