0

我在显示日期时遇到问题。该应用程序工作正常,但在实体中添加 DATE 后 - 停止。这是我的代码。有人可以帮助我吗?

堆栈跟踪:

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/pages/contact/showContacts.jsp at line 103

100:                    <td>${contact.email}</td>
101:                    <td>${contact.telephone}</td>
102:                    <td>${contact.department.name}</td>
103:                    <td>${contact.dateofemployment}</td>  
104:                        
105: 
106:                    <!--    <td><a href="delete/${contact.id}.html">delete</a></td>-->


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
...

Eclipse 异常(控制台):

SEVERE: Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'dateofemployment' not found on type pl.ivmx.model.Contact
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
    at javax.el.BeanELResolver.property(BeanELResolver.java:325)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:985)
    at org.apache.jasper.runtime.JspRuntimeLibrary.handleSetPropertyExpression(JspRuntimeLibrary.java:611)
    at org.apache.jsp.WEB_002dINF.pages.contact.showContacts_jsp._jspx_meth_c_005fforEach_005f1(showContacts_jsp.java:765)
    at org.apache.jsp.WEB_002dINF.pages.contact.showContacts_jsp._jspx_meth_c_005fif_005f4(showContacts_jsp.java:540)
    at org.apache.jsp.WEB_002dINF.pages.contact.showContacts_jsp._jspService(showContacts_jsp.java:185)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
...

接触:

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import pl.ivmx.model.Department;

@Entity
@Table(name="CONTACTS")
public class Contact {

    @Id
    @Column(name="ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(name="FIRSTNAME")
    private String firstname;

    @Column(name="LASTNAME")
    private String lastname;

    @Column(name="EMAIL")
    private String email;

    @Column(name="TELEPHONE")
    private int telephone;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "Department_ID", nullable = false)
    private Department department;

    @Column(name = "DATA_OF_EMPLOYMENT")
    @Temporal(TemporalType.DATE)
    private Date dateofemployment;


    public String getEmail() {
        return email;
    }
    public int getTelephone() {
        return telephone;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public void setTelephone(int telephone) {
        this.telephone = telephone;
    }
    public String getFirstname() {
        return firstname;
    }
    public String getLastname() {
        return lastname;
    }
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Department getDepartment() {
        return department;
    }
    public void setDepartment(Department department) {
        this.department = department;
    }
    public Date getDataDodania() {
        return dateofemployment;
    }
    public void setDataDodania(Date dateofemployment) {
        this.dateofemployment = dateofemployment;
    }

}

联系人控制器:

@Controller
public class ContactController  {


    @Autowired
    private ContactWebservice contactWebservice;

    @Autowired
    private DepartmentWebservice departmentWebservice;

    @Autowired
    private ContactFormValidator contactFormvalidator;

    @Autowired
    private DepartmentEditor departmentEditor;

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Department.class, this.departmentEditor);
    }



    int totalEditContacts = 0;                                                  //
    List<Integer> editedContacts = new ArrayList<Integer>();

    @RequestMapping(value="/showContacts", method=RequestMethod.GET)
    public ModelAndView listContacts(HttpServletRequest request,
            HttpServletResponse response ) throws ServletException, IOException{    

         ModelAndView mav = new ModelAndView("/contact/showContacts");

            List searchResults = contactWebservice.listContact();

            PagedListHolder pagedListHolder = new PagedListHolder(searchResults);
            int page = ServletRequestUtils.getIntParameter(request, "p", 0);
            pagedListHolder.setPage(page);
            int pageSize = 2;
            pagedListHolder.setPageSize(pageSize);
            mav.addObject("contactListHolder", pagedListHolder);

            mav.addObject("totalEditContacts", totalEditContacts);                



        return mav;
    }

showContacts.jsp

<%@include file="../header.jsp"%>

<%@include file="../menu.jsp"%>




<div id="main">



    <input type="button" value="New Contact"
        onclick="javascript:go('saveContact.do');" /> 

        <br><br>


    <!--    <c:if test="${empty contactListByFirstName}">
        <h3>List Contact's are empty</h3>
    </c:if>    -->

    <c:if test="${!empty contactListByFirstName}">
        <h3>Contacts</h3>
        <table class="tableshowall">
            <tr>
                <th>First name</th>
                <th>Last name</th>
                <th>Email</th>
                <th>Telephone</th>
                <th>Department</th>
                <th>Date of employment</th>
                <th>&nbsp;</th>
            </tr>
            <c:forEach items="${contactListByFirstName}" var="contact">
                <tr>
                    <td>${contact.firstname}</td>
                    <td>${contact.lastname}</td>
                    <td>${contact.email}</td>
                    <td>${contact.telephone}</td>
                    <td>${contact.department.name}</td>
                    <td>${contact.dateofemployment}</td>

                    <%--    <td><a href="delete/${contact.id}.html">delete</a></td>--%>
                    <td>&nbsp;<a href="updateContact.do?id=${contact.id}">Edit</a>
                        &nbsp;&nbsp;<a
                        href="javascript:deleteContact('deleteContact.do?id=${contact.id}');">delete</a>

                    </td>

                </tr>
            </c:forEach>
        </table>

        <br />





    </c:if>





    <%@ taglib prefix="tg" tagdir="/WEB-INF/tags"%>


    <c:if test="${!empty contactListHolder}">




        <%-- // create link for pages, "~" will be replaced later on with the proper page number --%>
        <c:url value="/showContacts.do" var="pagedLink">
            <c:param name="action" value="list" />
            <c:param name="p" value="~" />
        </c:url>

        <%-- // load our paging tag, pass pagedListHolder and the link --%>
        <tg:paging pagedListHolder="${contactListHolder}"
            pagedLink="${pagedLink}" />

        <%-- // show only current page worth of data --%>
        <table class="tableshowall">
            <tr>
                <th><spring:message code="contact.tableHeader.firstname" /></th>
                <th>Last name</th>
                <th>Email</th>
                <th>Telephone</th>
                <th>Department</th>
                <th>Date of employment</th>
                <th>&nbsp;</th>
            </tr>
            <c:forEach items="${contactListHolder.pageList}" var="contact">
                <tr>
                    <td>${contact.firstname}</td>
                    <td>${contact.lastname}</td>
                    <td>${contact.email}</td>
                    <td>${contact.telephone}</td>
                    <td>${contact.department.name}</td>
                    <td>${contact.dateofemployment}</td>  


                    <!--    <td><a href="delete/${contact.id}.html">delete</a></td>-->
                    <td>&nbsp;<a href="updateContact.do?id=${contact.id}">Edit</a>
                        &nbsp;&nbsp;<a
                        href="javascript:deleteContact('deleteContact.do?id=${contact.id}');">delete</a>

                    </td>

                </tr>
            </c:forEach>
        </table>

        <%-- // load our paging tag, pass pagedListHolder and the link --%>
        <tg:paging pagedListHolder="${contactListHolder}"
            pagedLink="${pagedLink}" />


        <form action="searchContacts.do" method="post">
            <table>
                <tr>
                    <td>Enter Contact Name</td>
                    <td><input type="text" name="firstname" /></td>
                    <td><input type="submit" value="Search" /></td>
                </tr>
            </table>
        </form> 



        total edit contacts:    <c:out value="${totalEditContacts}" />

    </c:if>


</div>

<%@ include file="../footer.jsp"%>
4

2 回答 2

3

dateofemployment类属性的getter 和 setter 方法Contact与属性名称不匹配。

要么将 getter/setter 方法更改为getDateofemployment/ setDateofemployment(与 JavaBeans 兼容),要么将 JSP 更改为使用${contact.dataDodania}.

另请注意,在 Java 中使用 camelCase 是最佳实践 -dateofemployment可能应该如此dateOfEmployment(使用匹配的 getter/setter 方法)。

于 2013-09-19T19:58:32.973 回答
1

在 ajsp中,EL(不要跳过它,阅读它)解决了这个问题

${contact.dateofemployment}

作为contact.getDateofemployment(),你没有。你有这个

public Date getDataDodania() {
    return dateofemployment;
}

将其重命名为getDateofemployment,它将起作用。或者,您可以使用 EL 表达式

${contact.dataDodania}

这同样适用于您的其他 EL 表达式。


在你使用的东西上保持一定的一致性,尤其是在语言方面。

于 2013-09-19T19:58:50.693 回答