Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用Servlet作为控制器和会话bean显示数据_Java_Jsp_Servlets_Netbeans_Ejb - Fatal编程技术网

Java 无法使用Servlet作为控制器和会话bean显示数据

Java 无法使用Servlet作为控制器和会话bean显示数据,java,jsp,servlets,netbeans,ejb,Java,Jsp,Servlets,Netbeans,Ejb,我当前正试图显示数据库中的属性列表。我已经使用工具支持从数据库自动生成了实体类。我创建了DAO类来访问实体类。我使用servlet访问DAO,并尝试将属性设置为从DAO类返回的结果,当我尝试使用JSTL foreach语句从JSP页面循环该属性时,它不起作用。这是我的密码: 财产实体: @Entity @Table(name = "PROPERTY") @XmlRootElement @NamedQueries({ @NamedQuery(name = "Property.findAll

我当前正试图显示数据库中的属性列表。我已经使用工具支持从数据库自动生成了实体类。我创建了DAO类来访问实体类。我使用servlet访问DAO,并尝试将属性设置为从DAO类返回的结果,当我尝试使用JSTL foreach语句从JSP页面循环该属性时,它不起作用。这是我的密码:

财产实体:

@Entity
@Table(name = "PROPERTY")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Property.findAll", query = "SELECT p FROM Property p")})
public class Property implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "PROPERTYID")
    private Integer propertyid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 500)
    @Column(name = "DESCRIPTION")
    private String description;
    @Size(max = 50)
    @Column(name = "TYPE")
    private String type;
    @Column(name = "NUMBEROFBEDROOM")
    private Integer numberofbedroom;
    @Column(name = "NUMBEROFBATHROOM")
    private Integer numberofbathroom;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "ISFURNISHED")
    private String isfurnished;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "HASGARDEN")
    private String hasgarden;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "SIZE")
    private String size;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "PRICE")
    private String price;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ENTEREDDATE")
    @Temporal(TemporalType.DATE)
    private Date entereddate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ENTEREDTIME")
    @Temporal(TemporalType.TIME)
    private Date enteredtime;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "property")
    private Paddress paddress;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "propertyid")
    private Collection<Offer> offerCollection;
    @JoinColumn(name = "PROPERTYOWNERID", referencedColumnName = "PROPERTYOWNERID")
    @ManyToOne(optional = false)
    private Propertyowner propertyownerid;
    @JoinColumn(name = "REALESTATEAGENTID", referencedColumnName = "REALESTATEAGENTID")
    @ManyToOne(optional = false)
    private Realestateagent realestateagentid;

    public Property() {
    }

    public Property(Integer propertyid) {
        this.propertyid = propertyid;
    }

    public Property(Integer propertyid, String description, String isfurnished, String hasgarden, String size, String price, Date entereddate, Date enteredtime) {
        this.propertyid = propertyid;
        this.description = description;
        this.isfurnished = isfurnished;
        this.hasgarden = hasgarden;
        this.size = size;
        this.price = price;
        this.entereddate = entereddate;
        this.enteredtime = enteredtime;
    }

    public Integer getPropertyid() {
        return propertyid;
    }

    public void setPropertyid(Integer propertyid) {
        this.propertyid = propertyid;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Integer getNumberofbedroom() {
        return numberofbedroom;
    }

    public void setNumberofbedroom(Integer numberofbedroom) {
        this.numberofbedroom = numberofbedroom;
    }

    public Integer getNumberofbathroom() {
        return numberofbathroom;
    }

    public void setNumberofbathroom(Integer numberofbathroom) {
        this.numberofbathroom = numberofbathroom;
    }

    public String getIsfurnished() {
        return isfurnished;
    }

    public void setIsfurnished(String isfurnished) {
        this.isfurnished = isfurnished;
    }

    public String getHasgarden() {
        return hasgarden;
    }

    public void setHasgarden(String hasgarden) {
        this.hasgarden = hasgarden;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public Date getEntereddate() {
        return entereddate;
    }

    public void setEntereddate(Date entereddate) {
        this.entereddate = entereddate;
    }

    public Date getEnteredtime() {
        return enteredtime;
    }

    public void setEnteredtime(Date enteredtime) {
        this.enteredtime = enteredtime;
    }

    public Paddress getPaddress() {
        return paddress;
    }

    public void setPaddress(Paddress paddress) {
        this.paddress = paddress;
    }

    @XmlTransient
    public Collection<Offer> getOfferCollection() {
        return offerCollection;
    }

    public void setOfferCollection(Collection<Offer> offerCollection) {
        this.offerCollection = offerCollection;
    }

    public Propertyowner getPropertyownerid() {
        return propertyownerid;
    }

    public void setPropertyownerid(Propertyowner propertyownerid) {
        this.propertyownerid = propertyownerid;
    }

    public Realestateagent getRealestateagentid() {
        return realestateagentid;
    }

    public void setRealestateagentid(Realestateagent realestateagentid) {
        this.realestateagentid = realestateagentid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (propertyid != null ? propertyid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Property)) {
            return false;
        }
        Property other = (Property) object;
        if ((this.propertyid == null && other.propertyid != null) || (this.propertyid != null && !this.propertyid.equals(other.propertyid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sushan.model.Property[ propertyid=" + propertyid + " ]";
    }

}
JSP页面:

<table border="1">
            <th>ID</th>
            <th>Description</th>
            <th>Type</th>
            <th>Number Of Bedroom</th>
            <th>Number Of Bathroom</th>
            <th>Furnished State</th>
            <th>Garden</th>
            <th>Size</th>
            <th>Price</th>
            <c:forEach items="${requestScope.allProperty}" var="p">
                <tr>
                    <td>${p.propertyID}</td>
                    <td>${p.description}</td>
                    <td>c:out value=${p.type}</td>
                    <td>c:out value=${p.numberOfBedroom}</td>
                    <td>c:out value=${p.numberOfBathroom}</td>
                    <td>c:out value=${p.isFurnished}</td>
                    <td>c:out value=${p.hasGarden}</td>
                    <td>c:out value=${p.size}</td>
                    <td>c:out value=${p.price}</td>
                </tr>
            </c:forEach>
        </table> 

身份证件
描述
类型
卧室数量
浴室数量
供应国
花园
大小
价格
${p.propertyID}
${p.description}
c:out值=${p.type}
c:out值=${p.numberof卧房}
c:out值=${p.numberOf}
c:out值=${p.isprofected}
c:out值=${p.hasGarden}
c:out值=${p.size}
c:out value=${p.price}
数据不会显示,也没有错误消息,而且jsp页面只有没有数据的表头。我在数据库的属性表中有数据


有什么我遗漏的吗?

您确定propertyDAO.GetAllProperty()正在返回列表吗。请检查一下。另外,在jsp页面中,您正在使用哪些页面指令。只需放置这段代码并签入jsp的page指令,将此属性isAligned=“false”示例:还要检查这个链接@AvinashReddy,它对我不起作用,而且我收到一个错误,说“javax.servlet.ServletException:Wrapper找不到servlet类com.sushan.controller.PropertyServlet或它所依赖的类”。::你的servlet类在包com.sushan.controller中吗?你在使用tomcat服务器吗?它的作用是什么您用来访问servlet的url是什么
import com.sushan.dao.PropertyDAOLocal;
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "PropertyServlet", urlPatterns = {"/PropertyServlet"})
public class PropertyServlet extends HttpServlet {

    @EJB
    private PropertyDAOLocal propertyDAO;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setAttribute("allProperty", propertyDAO.GetAllProperty());
        request.getRequestDispatcher("/AllProperty.jsp").forward(request, response);
        }
<table border="1">
            <th>ID</th>
            <th>Description</th>
            <th>Type</th>
            <th>Number Of Bedroom</th>
            <th>Number Of Bathroom</th>
            <th>Furnished State</th>
            <th>Garden</th>
            <th>Size</th>
            <th>Price</th>
            <c:forEach items="${requestScope.allProperty}" var="p">
                <tr>
                    <td>${p.propertyID}</td>
                    <td>${p.description}</td>
                    <td>c:out value=${p.type}</td>
                    <td>c:out value=${p.numberOfBedroom}</td>
                    <td>c:out value=${p.numberOfBathroom}</td>
                    <td>c:out value=${p.isFurnished}</td>
                    <td>c:out value=${p.hasGarden}</td>
                    <td>c:out value=${p.size}</td>
                    <td>c:out value=${p.price}</td>
                </tr>
            </c:forEach>
        </table>