显示日期时出现问题。应用程序工作正常,但在实体中添加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;
}
}
的ContactController:
@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> </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> <a href="updateContact.do?id=${contact.id}">Edit</a>
<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> </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> <a href="updateContact.do?id=${contact.id}">Edit</a>
<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"%>
答案 0 :(得分:3)
dateofemployment
类的Contact
属性的getter和setter方法与属性名称不匹配。
将getter / setter方法更改为getDateofemployment
/ setDateofemployment
(与JavaBeans兼容),或将JSP更改为使用${contact.dataDodania}
。
另请注意,最好在Java中使用camelCase - 因此dateofemployment
应该是dateOfEmployment
(使用匹配的getter / setter方法)。
答案 1 :(得分:1)
在jsp
,EL(不要跳过它,阅读它)解决此问题
${contact.dateofemployment}
作为contact.getDateofemployment()
,你没有。你有这个
public Date getDataDodania() {
return dateofemployment;
}
将其重命名为getDateofemployment
,它会起作用。或者,您可以使用EL表达式
${contact.dataDodania}
这同样适用于您的其他EL表达式。
保持一致性,特别是在语言方面。