Servlet,JPA,JSP - Servlet无法正常工作

时间:2015-12-07 19:15:18

标签: java jsp servlets jpa

我不知道为什么我的servlet不起作用。我的代码如下:

userOrdersServlet.java

public User getUser(int id) {
        this.em.clear();
        return this.em.find(User.class, id);
    }

userDAO.java

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<title>Library Online</title>
</head>
<body>
<div id="container">
    <%@include  file="templateTop.jsp" %>
<div class="main"><table border="1">
    <h2>Your orders</h2>
            <tr>
                <td>Title</td>
                <td>Author</td>
                <td>Description</td>
                <td>Category</td>
                <td>Year</td>
            </tr>
            <c:forEach var="booksOrdered" items="${booksOrderedByUser}">
                <tr>
                    <td>${booksOrdered.title}</td>
                    <td>${booksOrdered.author}</td>
                    <td>${booksOrdered.description}</td>
                    <td>${booksOrdered.category}</td>
                    <td>${booksOrdered.year}</td>
                    </tr>
            </c:forEach>
            </table>
    </div>
                    </div>
            <div style="clear:both"></div>

    <br>


</body>
</html>

userOrders.jsp

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>RegisterLoginJPA</display-name>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>sessionFilter</filter-name>
<filter-class>filters.sessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>/loginSuccess.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
</web-app>

的web.xml

userOrdersServlet.java

所以我使用了来自System.out.println()的代码并使用foreach循环和userOrders.jsp在另一个servlet中显示数据,并且它可以正常工作。但是当我去app.js时,它没有显示任何数据,我做错了什么?

1 个答案:

答案 0 :(得分:0)

要访问JSP中的请求参数,您需要在参数名称前加上“param”。所以

<c:forEach var="booksOrdered" items="${booksOrderedByUser}">

应该是:

<c:forEach var="booksOrdered" items="${param.booksOrderedByUser}">

请参阅:JSP Expression Language get parameter