我正在开发一个Spring-MVC应用程序。我有多个服务类,它们都被映射到一个控制器类。这是一种“笔记”应用程序。这就是有许多模型,服务的原因,但一切都在一个网页上。现在,我可以添加一个注释,删除一个注释,但编辑不起作用。之前我只有一个dao,model,service,controller,edit用来工作。现在我得到404.我发布了控制器和JSP / HTML文件。请看看。编辑没有工作,所以随意选择其中任何一个。任何,任何指针都会有所帮助。 控制器类:
@Controller
public class PersonController {
private PersonService personService;
private KeyActivitiesService keyActivitiesService;
private KernresourcenService kernresourcenService;
private WertangebotService wertangebotService;
private KundenhungenService kundenhungenService;
private KommService kommService;
@Autowired(required = true)
@Qualifier(value="personService")
public void setPersonService(PersonService ps){
this.personService = ps;
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public String listPersons(Model model) {
model.addAttribute("person", new Person());
model.addAttribute("keyactivities", new KeyActivities());
model.addAttribute("kernnotices", new Kernresourcen());
model.addAttribute("wertnotices", new Wertangebot());
model.addAttribute("kundNotices", new Kundenhungen());
model.addAttribute("kommnotices", new KommunikationNotice());
model.addAttribute("listPersons", this.personService.listPersons());
model.addAttribute("listNotices", this.keyActivitiesService.listNotices());
model.addAttribute("listKernNotices", this.kernresourcenService.listKernNotices());
model.addAttribute("listWertNotices", this.wertangebotService.listWertNotices());
model.addAttribute("listKundNotices", this.kundenhungenService.listKundNotices());
model.addAttribute("listKommNotices", this.kommService.listKommNotices());
return "person";
}
//For add and update person both
@RequestMapping(value= "/person/add", method = RequestMethod.POST)
public String addPerson(@ModelAttribute("person") Person p){
//new person, add it
this.personService.addPerson(p);
return "redirect:/";
}
@RequestMapping("/remove/{id}")
public String removePerson(@PathVariable("id") Integer id){
this.personService.removePerson(id);
return "redirect:/";
}
@RequestMapping("/edit/{id}")
public String editPerson(@PathVariable("id") Integer id, Model model){
model.addAttribute("person", this.personService.getPersonById(id));
model.addAttribute("listPersons", this.personService.listPersons());
return "person";
}
// Here we start with keyactivities controller
@Autowired(required = true)
@Qualifier(value="keyactivitiesservice")
public void setKeyActivitiesService(KeyActivitiesService keyActivitiesService){this.keyActivitiesService = keyActivitiesService;}
// @RequestMapping(value = "/keynotice/listNotices", method = RequestMethod.GET)
public String listKeyNotices(Model model) {
model.addAttribute("keyactivities", new KeyActivities());
model.addAttribute("listNotices", this.keyActivitiesService.listNotices());
return "keyactivities";
}
//For add and update person both
@RequestMapping(value= "/keynotice/add", method = RequestMethod.POST)
public String addKeyNotice(@ModelAttribute("keyactivities") KeyActivities p){
//new person, add it
this.keyActivitiesService.addKeyNotice(p);
return "redirect:/";
}
@RequestMapping("/removenotice/{id}")
public String removeKeyNotice(@PathVariable("id") Integer id){
this.keyActivitiesService.removeNotice(id);
return "redirect:/";
}
@RequestMapping("/editnotice/{id}")
public String editKeyNotice(@PathVariable("id") Integer id, Model model){
model.addAttribute("keyactivities", this.keyActivitiesService.getNoticeById(id));
model.addAttribute("keyactivities", this.keyActivitiesService.listNotices());
return "keyactivities";
}
//kernesourcen starts
@Autowired(required = true)
@Qualifier(value = "kernresourcenService")
public void setKernresourcenService(KernresourcenService kernresourcenService){this.kernresourcenService = kernresourcenService;}
// @RequestMapping(value = "/kernnotice/listKernNotices", method = RequestMethod.GET)
public String listKernNotices(Model model) {
model.addAttribute("kernnotices", new Kernresourcen());
model.addAttribute("listKernNotices", this.kernresourcenService.listKernNotices());
return "kernnotices";
}
//For add and update person both
@RequestMapping(value= "/kernnotice/add", method = RequestMethod.POST)
public String addkernNotice(@ModelAttribute("kernnotices") Kernresourcen p){
//new person, add it
this.kernresourcenService.addKernNotice(p);
return "redirect:/";
}
@RequestMapping("/removekernNotice/{id}")
public String removeKernNotice(@PathVariable("id") Integer id){
this.kernresourcenService.removeKernNotice(id);
return "redirect:/";
}
@RequestMapping("/editkernnotice/{id}")
public String editKernNotice(@PathVariable("id") Integer id, Model model){
model.addAttribute("kernnotices", this.kernresourcenService.getKernNoticenById(id));
model.addAttribute("kernnotices", this.kernresourcenService.listKernNotices());
return "kernnotices";
}
// Wertangebot controller starts here
@Autowired(required = true)
@Qualifier(value = "wertnoticesservice")
public void setWertangebotService(WertangebotService wertangebotService){this.wertangebotService = wertangebotService;}
// @RequestMapping(value = "/wertnotice/listWertNotice", method = RequestMethod.GET)
public String listWertNotices(Model model) {
model.addAttribute("wertnotices", new Wertangebot());
model.addAttribute("listWertNotices", this.wertangebotService.listWertNotices());
return "wertnotices";
}
//For add and update person both
@RequestMapping(value= "/wertnotice/add", method = RequestMethod.POST)
public String addWertnotice(@ModelAttribute("wertnotices") Wertangebot p){
//new person, add it
this.wertangebotService.addWertNotice(p);
return "redirect:/";
}
@RequestMapping("/removewertnotice/{id}")
public String removeWertNotice(@PathVariable("id") Integer id){
this.wertangebotService.removeWertNotice(id);
return "redirect:/";
}
@RequestMapping("/editwertnotice/{id}")
public String editWertNotice(@PathVariable("id") Integer id, Model model){
model.addAttribute("wertnotices", this.wertangebotService.getWertNoticenById(id));
model.addAttribute("wertnotices", this.wertangebotService.listWertNotices());
return "wertnotices";
}
//Kundenhungen controller starts here
@Autowired(required = true)
@Qualifier(value = "kundenhungenService")
public void setKundenhungenService(KundenhungenService kundenhungenService){this.kundenhungenService=kundenhungenService;}
// @RequestMapping(value = "/wertnotice/listWertNotice", method = RequestMethod.GET)
public String listKundNotices(Model model) {
model.addAttribute("kundNotices", new Kundenhungen());
model.addAttribute("listKundNotices", this.kundenhungenService.listKundNotices());
return "kundNotices";
}
//For add and update person both
@RequestMapping(value= "/kundnotice/add", method = RequestMethod.POST)
public String addKundnotice(@ModelAttribute("kundNotices") Kundenhungen p){
//new person, add it
this.kundenhungenService.addKundNotice(p);
return "redirect:/";
}
@RequestMapping("/removekundnotice/{id}")
public String removeKundNotice(@PathVariable("id") Integer id){
this.kundenhungenService.removeKundNotice(id);
return "redirect:/";
}
@RequestMapping("/editkundnotice/{id}")
public String editKundNotice(@PathVariable("id") Integer id, Model model){
model.addAttribute("kundNotices", this.kundenhungenService.getKundNoticeById(id));
model.addAttribute("kundNotices", this.kundenhungenService.listKundNotices());
return "kundNotices";
}
//Kommunikationsnotice controller starts here.
@Autowired(required = true)
@Qualifier(value = "kommService")
public void setKommService(KommService kommService){this.kommService=kommService;}
// @RequestMapping(value = "/wertnotice/listWertNotice", method = RequestMethod.GET)
public String listKommNotices(Model model) {
model.addAttribute("kommnotices", new KommunikationNotice());
model.addAttribute("listKommNotices", this.kommService.listKommNotices());
return "kommnotices";
}
//For add and update person both
@RequestMapping(value= "/kommnotice/add", method = RequestMethod.POST)
public String addKommnotice(@ModelAttribute("kommnotices") KommunikationNotice p){
//new person, add it
this.kommService.addKommNotice(p);
return "redirect:/";
}
@RequestMapping("/removekommnotice/{id}")
public String removeKommNotice(@PathVariable("id") Integer id){
this.kommService.removeKommNotice(id);
return "redirect:/";
}
@RequestMapping("/editkommnotice/{id}")
public String editKommNotice(@PathVariable("id") Integer id, Model model){
model.addAttribute("kommnotices", this.kommService.getKommNoticeById(id));
model.addAttribute("kommnotices", this.kommService.listKommNotices());
return "kommnotices";
}
}
JSP文件
<c:url var="addAction" value="/person/add" ></c:url>
<form:form action="${addAction}" commandName="person">
<table>
<c:if test="${!empty person.name}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="name">
<spring:message text="Name"/>
</form:label>
</td>
<td>
<form:input path="name" />
</td>
</tr>
<tr>
<td colspan="1">
<c:if test="${!empty person.name}">
<input type="submit"
value="<spring:message text="Edit Partner"/>" />
</c:if>
<c:if test="${empty person.name}">
<input type="submit"
value="<spring:message text="Add Partner"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<h3>Partners List</h3>
<c:if test="${!empty listPersons}">
<table class="tg">
<tr>
<th width="120">Partner Name</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listPersons}" var="person">
<tr>
<td>${person.name}</td>
<td><a href="<c:url value='/edit/${person.id}' />" >Edit</a></td>
<td><a href="<c:url value='/remove/${person.id}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
<br>
<c:url var="addAction" value="/keynotice/add" ></c:url>
<form:form action="${addAction}" commandName="keyactivities">
<table>
<c:if test="${!empty keyactivities.keynotice}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="keynotice">
<spring:message text="keynotice"/>
</form:label>
</td>
<td>
<form:input path="keynotice" />
</td>
</tr>
<tr>
<td colspan="1">
<c:if test="${!empty keyactivities.keynotice}">
<input type="submit"
value="<spring:message text="Edit Kernaktivitaten"/>" />
</c:if>
<c:if test="${empty keyactivities.keynotice}">
<input type="submit"
value="<spring:message text="Add Kernaktivitaten"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<h3>Kernaktivaten List</h3>
<c:if test="${!empty listNotices}">
<table class="tg">
<tr>
<th width="120">Kernaktivaten Name</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listNotices}" var="keyactivities">
<tr>
<td>${keyactivities.keynotice}</td>
<td><a href="<c:url value='/editnotice/${keyactivities.id}' />" >Edit</a></td>
<td><a href="<c:url value='/removenotice/${keyactivities.id}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
<c:url var="addAction" value="/kernnotice/add" ></c:url>
<form:form action="${addAction}" commandName="kernnotices">
<table>
<c:if test="${!empty kernnotices.kernresourcenNotice}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="kernresourcenNotice">
<spring:message text="kernresourcenNotice"/>
</form:label>
</td>
<td>
<form:input path="kernresourcenNotice" />
</td>
</tr>
<tr>
<td colspan="1">
<c:if test="${!empty kernnotices.kernresourcenNotice}">
<input type="submit"
value="<spring:message text="Edit Kernnotice"/>" />
</c:if>
<c:if test="${empty person.name}">
<input type="submit"
value="<spring:message text="Add Kernnotice"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<h3>kernensourcen List</h3>
<c:if test="${!empty listKernNotices}">
<table class="tg">
<tr>
<th width="120">Kernnotice Name</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listKernNotices}" var="kernnotices">
<tr>
<td>${kernnotices.kernresourcenNotice}</td>
<td><a href="<c:url value='/editkernnotice/${kernnotices.id}' />" >Edit</a></td>
<td><a href="<c:url value='/removekernNotice/${kernnotices.id}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
<c:url var="addAction" value="/wertnotice/add" ></c:url>
<form:form action="${addAction}" commandName="wertnotices">
<table>
<c:if test="${!empty wertnotices.wertangebotNotice}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="wertangebotNotice">
<spring:message text="wertangebotNotice"/>
</form:label>
</td>
<td>
<form:input path="wertangebotNotice" />
</td>
</tr>
<tr>
<td colspan="1">
<c:if test="${!empty wertnotices.wertangebotNotice}">
<input type="submit"
value="<spring:message text="Edit Wertnotice"/>" />
</c:if>
<c:if test="${empty wertnotices.wertangebotNotice}">
<input type="submit"
value="<spring:message text="Add Wertnotice"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<h3>Wertangebot List</h3>
<c:if test="${!empty listWertNotices}">
<table class="tg">
<tr>
<th width="120">Wertnotice Name</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listWertNotices}" var="wertnotices">
<tr>
<td>${wertnotices.wertangebotNotice}</td>
<td><a href="<c:url value='/editwertnotice/${wertnotices.id}' />" >Edit</a></td>
<td><a href="<c:url value='/removewertnotice/${wertnotices.id}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
<c:url var="addAction" value="/kundnotice/add" ></c:url>
<form:form action="${addAction}" commandName="kundNotices">
<table>
<c:if test="${!empty kundNotices.kundennotice}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="kundennotice">
<spring:message text="kundennotice"/>
</form:label>
</td>
<td>
<form:input path="kundennotice" />
</td>
</tr>
<tr>
<td colspan="1">
<c:if test="${!empty kundNotices.kundennotice}">
<input type="submit"
value="<spring:message text="Edit Kundennotice"/>" />
</c:if>
<c:if test="${empty kundNotices.kundennotice}">
<input type="submit"
value="<spring:message text="Add Kundennotice"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<h3>Kundennotices List</h3>
<c:if test="${!empty listKundNotices}">
<table class="tg">
<tr>
<th width="120">kundennotice Name</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listKundNotices}" var="kundennotices">
<tr>
<td>${kundennotices.kundennotice}</td>
<td><a href="<c:url value='/editkundnotice/${kundennotices.id}' />" >Edit</a></td>
<td><a href="<c:url value='/removekundnotice/${kundennotices.id}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
<c:url var="addAction" value="/kommnotice/add" ></c:url>
<form:form action="${addAction}" commandName="kommnotices">
<table>
<c:if test="${!empty kommnotices.kommnotice}">
<tr>
<td>
<form:label path="id">
<spring:message text="ID"/>
</form:label>
</td>
<td>
<form:input path="id" readonly="true" size="8" disabled="true" />
<form:hidden path="id" />
</td>
</tr>
</c:if>
<tr>
<td>
<form:label path="kommnotice">
<spring:message text="kommnotice"/>
</form:label>
</td>
<td>
<form:input path="kommnotice" />
</td>
</tr>
<tr>
<td colspan="1">
<c:if test="${!empty kommnotices.kommnotice}">
<input type="submit"
value="<spring:message text="Edit Kommnotice"/>" />
</c:if>
<c:if test="${empty kommnotices.kommnotice}">
<input type="submit"
value="<spring:message text="Add Kommnotice"/>" />
</c:if>
</td>
</tr>
</table>
</form:form>
<h3>Kommnotices List</h3>
<c:if test="${!empty listKommNotices}">
<table class="tg">
<tr>
<th width="120">Kommnotices Name</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listKommNotices}" var="kommnotices">
<tr>
<td>${kommnotices.kommnotice}</td>
<td><a href="<c:url value='/editkommnotice/${kommnotices.id}' />" >Edit</a></td>
<td><a href="<c:url value='/removekommnotice/${kommnotices.id}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
编辑时404的网址链接:
http://localhost:8085/mvcmanage-1.0-SNAPSHOT/editnotice/300
http://localhost:8085/mvcmanage-1.0-SNAPSHOT/editkernnotice/200
http://localhost:8085/mvcmanage-1.0-SNAPSHOT/editwertnotice/150
http://localhost:8085/mvcmanage-1.0-SNAPSHOT/editkundnotice/250
http://localhost:8085/mvcmanage-1.0-SNAPSHOT/editkommnotice/200
对于以上所有,我得到了404
新错误日志:(点击人物编辑后)
SEVERE: Servlet.service() for servlet [appServlet] in context with path [] threw exception [An exception occurred processing JSP page /WEB-INF/views/person.jsp at line 380
377: </c:if>
378: <tr>
379: <td>
380: <form:label path="keynotice">
381: <spring:message text="keynotice"/>
382: </form:label>
383: </td>
Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'keyactivities' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:130)
at org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:120)
at org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:90)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.views.person_jsp._jspx_meth_form_005flabel_005f3(person_jsp.java:1969)
at org.apache.jsp.WEB_002dINF.views.person_jsp._jspx_meth_form_005fform_005f1(person_jsp.java:1740)
at org.apache.jsp.WEB_002dINF.views.person_jsp._jspService(person_jsp.java:395)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
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:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
答案 0 :(得分:1)
通常,这些是使用Spring MVC获取404
的最常见原因:
<jsp:include >
个依赖项(这适用于整个包含链)检查您是否遇到任何问题。