我的cmpmstaddedit.jsp'中出现以下错误:
org.springframework.beans.NotReadablePropertyException:无效 财产' cmpcode' bean类[java.util.ArrayList]:Bean属性 ' cmpcode'不可读或具有无效的getter方法:是吗? getter的返回类型是否与setter的参数类型相匹配? org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:725) org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:716) org.springframework.web.servlet.support.BindStatus。(BindStatus.java:149) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116) org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422) org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142) org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84) org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80) org.apache.jsp.WEB_002dINF.views.admin.cmpmstmgmt_jsp._jspx_meth_form_005finput_005f0(cmpmstmgmt_jsp.java:330) org.apache.jsp.WEB_002dINF.views.admin.cmpmstmgmt_jsp._jspx_meth_form_005fform_005f0(cmpmstmgmt_jsp.java:269) org.apache.jsp.WEB_002dINF.views.admin.cmpmstmgmt_jsp._jspService(cmpmstmgmt_jsp.java:123) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:618) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:85) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
文件' cmpmstaddedit.jsp'如下:
<%--
Document : cmpmstaddedit
Created on : Aug 3, 2014, 1:18:10 PM
--%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:url var="actionUrl" value="save" />
<form:form id="cmpmstForm" commandName="cmpmsts" method="post" action="${actionUrl}" class="pure-form pure-form-aligned">
<fieldset>
<legend></legend>
<div class="pure-control-group">
<label for="cmpcode">Code</label>
<form:input path="cmpcode" placeholder="Company Code" maxlength="15" />
</div>
<div class="pure-control-group">
<label for="cmpdescr">Price</label>
<form:input path="cmpdescr" placeholder="Company Description" maxlength="30" />
</div>
<div class="pure-control-group">
<label for="cmpfybegin">Price</label>
<form:input path="cmpfybegin" placeholder="F.Y. Begin Date" maxlength="15" />
</div>
<div class="pure-control-group">
<label for="cmpfyend">Price</label>
<form:input path="cmpfyend" placeholder="F.Y. End Date" maxlength="15" />
</div>
</fieldset>
</form:form>
我的模型文件&#39; CmpMst.java&#39;如下:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.nej.cmpmst.model;
/**
*
*/
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="cmpmst", catalog = "nioerpj")
public class CmpMst {
@Id
private Byte cmpcode;
private String cmpdescr;
private Date cmpfybegin;
private Date cmpfyend;
public Byte getCmpcode() {
return cmpcode;
}
public void setCmpcode(Byte cmpcode) {
this.cmpcode = cmpcode;
}
public String getCmpdescr() {
return cmpdescr;
}
public void setCmpdescr(String cmpdescr) {
this.cmpdescr = cmpdescr;
}
public Date getCmpfybegin() {
return cmpfybegin;
}
public void setCmpfybegin(Date cmpfybegin) {
this.cmpfybegin = cmpfybegin;
}
public Date getCmpfyend() {
return cmpfyend;
}
public void setCmpfyend(Date cmpfyend) {
this.cmpfyend = cmpfyend;
}
}
我搜索了互联网,发现了很多类似的案例,但是,即使应用了给定的解决方案,也没有解决我的问题。有人可以帮助解决问题吗?我是否需要上传任何其他文件才能得出结论?
编辑:
我的控制器文件CmpMstController.java如下:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.nej.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.nej.cmpmst.model.CmpMst;
import com.nej.cmpmst.service.CmpMstService;
/**
*
*/
@Controller
@RequestMapping(value={"/admin/cmpmstmgmt"})
public class CmpMstController {
@Autowired
private CmpMstService cmpmstService;
@RequestMapping(value="/add", method=RequestMethod.GET)
public ModelAndView addCmpMstPage() {
ModelAndView modelAndView = new ModelAndView("CmpMst-add");
modelAndView.addObject("cmpmstmgmt", new CmpMst());
return modelAndView;
}
@RequestMapping(value="/add", method=RequestMethod.POST)
public ModelAndView addingCmpMst(@ModelAttribute CmpMst cmpmst) {
ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
cmpmstService.addCmpMst(cmpmst);
String message = "CmpMst was successfully added.";
modelAndView.addObject("message", message);
return modelAndView;
}
@RequestMapping(value={"/list","/"})
public ModelAndView listOfCmpMsts() {
ModelAndView modelAndView = new ModelAndView("/admin/cmpmstmgmt");
List<CmpMst> cmpmsts = cmpmstService.getCmpMsts();
modelAndView.addObject("cmpmsts", cmpmsts);
return modelAndView;
}
@RequestMapping(value="/edit/{cmpcode}", method=RequestMethod.GET)
public ModelAndView editCmpMstPage(@PathVariable Byte cmpcode) {
ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
CmpMst cmpmst = cmpmstService.getCmpMst(cmpcode);
modelAndView.addObject("cmpmst",cmpmst);
return modelAndView;
}
@RequestMapping(value="/edit/{cmpcode}", method=RequestMethod.POST)
public ModelAndView editingCmpMst(@ModelAttribute CmpMst cmpmst, @PathVariable Byte cmpcode) {
ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
cmpmstService.updateCmpMst(cmpmst);
String message = "CmpMst was successfully edited.";
modelAndView.addObject("message", message);
return modelAndView;
}
@RequestMapping(value="/delete/{cmpcode}", method=RequestMethod.GET)
public ModelAndView deleteCmpMst(@PathVariable Byte cmpcode) {
ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
cmpmstService.deleteCmpMst(cmpcode);
String message = "CmpMst was successfully deleted.";
modelAndView.addObject("message", message);
return modelAndView;
}
}
我的cmpmstmgmt.jsp如下:
<%--
Document : cmpmstmgmt
Created on : Jul 26, 2014, 6:00:28 PM
Author : Tushar
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<tiles:insertDefinition name="defaultTemplate">
<tiles:putAttribute name="body">
<link rel="stylesheet" href='<c:url value="../../../resources/mytheme/styles/pure-0.4.2.css"/>'>
<link rel="stylesheet" href='<c:url value="../../../resources/mytheme/styles/jquery-ui.css"/>'>
<style type="text/css">
th {
text-align: left
}
</style>
<div class="body">
<div style="width: 95%; margin: 0 auto;">
<div id="bookDialog" style="display: none;">
<%@ include file="cmpmstaddedit.jsp"%>
</div>
<h1>List Of Company Master</h1>
<button class="pure-button pure-button-primary" onclick="addCmpMst()">
<i class="fa fa-plus"></i> Add Company Master
</button>
<br>
<table class="pure-table pure-table-bordered pure-tablestriped">
<thead>
<tr>
<th width="4%">Sr.No.</th>
<th width="12%">Code</th>
<th width="12%">Company Description</th>
<th width="12%">F.Y. Begin Date</th>
<th width="12%">F.Y. End Date</th>
<th width="12%"></th>
</tr>
</thead>
<tbody>
<c:forEach items="${cmpmst}" var="user" varStatus="loopCounter">
<tr>
<td><c:out value="${loopCounter.count}" /></td>
<td><c:out value="${cmpmst.cmpcode}" /></td>
<td><c:out value="${cmpmst.cmpdescr}" /></td>
<td><c:out value="${cmpmst.cmpfybegin}" /></td>
<td><c:out value="${cmpmst.cmpfyend}" /></td>
<td>
<nobr>
<button onclick="editCmpMst(${cmpmst.cmpcode});"
class="pure-button pure-buttonprimary">
<i class="fa fa-pencil"></i> Edit
</button>
<a href="delete/${cmpmst.cmpcode}" class="pure-button pure-button-primary" onclick="return confirm('Are you sure you want to delete this CmpMst?');">
<i class="fa fa-times"></i>Delete
</a>
</nobr>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<!-- It is advised to put the <script> tags at the end of the document body so that they don't block rendering of the page -->
<script type="text/javascript" src='<c:url value="../../../resources/mytheme/script/jquery.js" />'></script>
<script type="text/javascript" src='<c:url value="../../../resources/mytheme/script/jquery-ui.js" />'></script>
<script type="text/javascript" src='<c:url value="../../../resources/mytheme/script/js-for-listuser.js"/>'></script>
</div>
</tiles:putAttribute>
</tiles:insertDefinition>
我已经上传了控制器文件 - CmpMstController.java和cmpmstmgmt.jsp文件,如上所述。请建议更正。
type Exception report
message An exception occurred processing JSP page /WEB-INF/views/admin/cmpmstaddedit.jsp at line 16
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/admin/cmpmstaddedit.jsp at line 16
13: <legend></legend>
14: <div class="pure-control-group">
15: <label for="cmpcode">Code</label>
16: <form:input path="cmpcode" placeholder="Company Code" maxlength="15" />
17: </div>
18: <div class="pure-control-group">
19: <label for="cmpdescr">Company Description</label>
编辑:文件 - js-for-listcmpmst.js
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
function addCmpMst() {
$('#cmpmstDialog').dialog("option", "title", 'Add Company');
$('#cmpmstDialog').dialog('open');
}
function editCmpMst(cmpcode) {
$.get("get/" + cmpcode, function(result) {
$("#cmpmstDialog").html(result);
$('#cmpmstDialog').dialog("option", "title", 'Edit Company');
$("#cmpmstDialog").dialog('open');
initializeDatePicker();
});
}
function initializeDatePicker() {
$(".datepicker").datepicker({
dateFormat : "dd/mm/yyyy",
changeMonth : true,
changeYear : true,
showButtonPanel : true
});
}
function resetDialog(form) {
form.find("input").val("");
}
$(document).ready(function() {
$('#cmpmstDialog').dialog({
autoOpen : false,
position : 'center',
modal : true,
resizable : false,
width : 440,
buttons : {
"Save" : function() {
$('#cmpmstForm').submit();
},
"Cancel" : function() {
$(this).dialog('close');
}
},
close : function() {
resetDialog($('#cmpmstForm'));
$(this).dialog('close');
}
});
initializeDatePicker();
});
已编辑的控制器文件:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.nej.controller;
import com.nej.cmpmst.model.CmpMst;
import com.nej.cmpmst.service.CmpMstService;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
*
* @author Tushar
*/
@Controller
@RequestMapping(value={"/admin/cmpmstmgmt"})
public class CmpMstController {
@Autowired
private CmpMstService cmpmstService;
@RequestMapping(value={"/list","/"})
public String listOfCmpMsts(Map<String, Object> map ) {
map.put("cmpmst", new CmpMst());
map.put("cmpmstList", cmpmstService.getCmpMsts());
return "/admin/cmpmstmgmt";
}
@RequestMapping("get/{cmpcode}")
public String getCmpMst(@PathVariable Byte cmpcode, Map<String, Object> map) {
CmpMst cmpmst = cmpmstService.getCmpMst(cmpcode);
map.put("cmpmst", cmpmst);
return "admin/cmpmstaddedit";
}
@RequestMapping(value="/save", method = RequestMethod.POST)
public String saveCmpMst(@ModelAttribute("cmpmst") CmpMst cmpmst, BindingResult result) {
cmpmstService.saveCmpMst(cmpmst);
return "redirect:list";
}
@RequestMapping("/delete/{cmpcode}")
public String deleteCmpMst(@PathVariable("cmpcode") Byte cmpcode) {
cmpmstService.deleteCmpMst(cmpcode);
return "redirect:/admin/cmpmstmgmt/";
}
}
cmpmstaddedit.jsp
<%--
Document : cmpmstaddedit
Created on : Aug 3, 2014, 1:18:10 PM
Author : Tushar
--%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:url var="actionUrl" value="save" />
<form:form id="cmpmstaddedit" commandName="cmpmst" method="post" action="${actionUrl}" class="pure-form pure-form-aligned">
<fieldset>
<legend></legend>
<div class="pure-control-group">
<label for="cmpcode">Code</label>
<form:input path="cmpcode" placeholder="Company Code" maxlength="15" />
</div>
<div class="pure-control-group">
<label for="cmpdescr">Company Description</label>
<form:input path="cmpdescr" placeholder="Company Description" maxlength="30" />
</div>
<div class="pure-control-group">
<label for="cmpfybegin">F.Y. Begin Date</label>
<form:input path="cmpfybegin" placeholder="DD/MM/YYYY" class="datepicker" />
</div>
<div class="pure-control-group">
<label for="cmpfyend">F.Y. End Date</label>
<form:input path="cmpfyend" placeholder="DD/MM/YYYY" class="datepicker" />
</div>
</fieldset>
</form:form>
答案 0 :(得分:1)
在JSP文件中:
<c:forEach items="${cmpmst}" var="user" varStatus="loopCounter">
<tr>
<td><c:out value="${loopCounter.count}" /></td>
<td><c:out value="${cmpmst.cmpcode}" /></td>
而${cmpmst}
是数组。你应该写:
<c:forEach items="${cmpmst}" var="user" varStatus="loopCounter">
<tr>
<td><c:out value="${loopCounter.count}" /></td>
<td><c:out value="${user.cmpcode}" /></td>
和以下字段相同
我无法看到您在显示的控制器中转发到cmpmstaddedit.jsp
的方式和位置,但我认为cmpmsts
也是一个列表。您必须确保在转发到该视图之前将单个对象作为请求属性。