我得到这个错误: HTTP Status 405 - Request method 'POST' not supported
我要做的是创建一个带有下拉框的表单,该表单将根据在另一个下拉框中选择的其他值进行填充.例如,当我在customerName
框中选择一个名称时,onChange
应运行.jsp页面中的函数,然后提交页面,然后再次使用customerCountry
框中的相应值加载.
但是我收到此HTTP状态405错误.我已经在互联网上搜索了一个解决方案,但却找不到任何有用的东西.这是我的代码的相关部分:
jsp页面的一部分
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
.error { color: red; }
</style>
<script>
function repopulate(){
document.deliveryForm.submit();
}
function setFalse(){
document.getElementById("hasId").value ="false";
document.deliveryForm.submit();
// document.submitForm.submit(); (This was causing the error)
}
</script>
</head>
<body>
<h1>Create New Delivery</h1>
<c:url var="saveUrl" value="/test/delivery/add" />
<form:form modelAttribute="deliveryDtoAttribute" method="POST" action="${saveUrl}" name="deliveryForm">
<table>
<tr>
<td><form:hidden id="hasId" path="hasCustomerName" value="true"/></td>
</tr>
<tr>
<td>Customer Name</td>
<td><form:select path="customerName" …
Run Code Online (Sandbox Code Playgroud) 我需要帮助修复我在尝试将我的Web应用程序部署到tomcat时遇到的错误.为什么不定义customerService bean?我在web.xml中遗漏了什么,或者我必须以某种方式映射customerService?我正在使用注释进行映射.任何帮助将非常感激.以下是localhost日志中的错误日志条目:
错误:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'customerService' is defined
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4600)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5097)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5092)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at …
Run Code Online (Sandbox Code Playgroud) 我一直试图找出如何填充Spring MVC中的下拉框.关于这个问题有一些主题,但我找到的没有一个帮助过我,所以我希望有人可以帮助我.
这是我的控制器:
@Controller
@RequestMapping("/document-revision")
public class DocumentRevisionController {
@Autowired
private DocumentRevisionService documentRevisionService;
private DocumentService documentService;
@RequestMapping(value="/list", method=RequestMethod.GET)
public String getDocumentRevisionList(Model model) {
List<DocumentRevision> documentRevisions = documentRevisionService.retrieveAllDocumentRevisions();
model.addAttribute("documentRevisions", documentRevisions);
return "document-revision";
}
@RequestMapping(value="/add", method=RequestMethod.GET)
public String getDocumentRevision(Model model) {
DocumentRevision documentRevision = new DocumentRevision();
model.addAttribute("documentRevisionAttribute", documentRevision);
return "new-documnent-revision";
}
@RequestMapping(value="/add", method=RequestMethod.POST)
public String postDocumentRevision(@ModelAttribute("documentRevisionAttribute") @Valid DocumentRevision documentRevision, BindingResult result) {
if(result.hasErrors()){
return "new-document-revision";
}
documentRevisionService.createDocumentRevision(documentRevision);
return "redirect:/testapp/document-revision/list";
}
}
Run Code Online (Sandbox Code Playgroud)
这是jsp页面:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> …
Run Code Online (Sandbox Code Playgroud) 我尝试提交表单时收到以下验证错误.使用Document.java中的值填充的下拉框会出现此错误:
Failed to convert property value of type java.lang.String to required type
testapp.domain.Document for property document_number; nested exception is
java.lang.IllegalStateException: Cannot convert value of type [java.lang.String]
to required type [testapp.domain.Document] for property document_number: no matching
editors or conversion strategy found
Run Code Online (Sandbox Code Playgroud)
我的映射有问题吗?
Document.java映射
@OneToMany(mappedBy="document_number", cascade = CascadeType.ALL)
private Set<DocumentRevision> documentRevisions;
public void setDocumentRevisions(Set<DocumentRevision> documentRevisions){
this.documentRevisions = documentRevisions;
}
Run Code Online (Sandbox Code Playgroud)
DocumentRevision.java映射
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="DOCUMENT_NUMBER")
private Document document_number;
public void setDocument_number(Document document_number){
this.document_number = document_number;
}
public Document getDocument_number(){
return document_number;
}
Run Code Online (Sandbox Code Playgroud)
两个表之间的关系是几个 …
我正在尝试向我的网络应用添加编辑功能,但我在使用时遇到了一些问题@RequestParam
.它获得的参数是null,它不应该是.我希望有人可以指出我犯了什么错误.
以下是控制器的方法:
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String getEdit(@RequestParam("customerId") Integer customerId, Model model) {
Customer existingCustomer = customerService.retrieveCustomer(customerId);
model.addAttribute("customerAttribute", existingCustomer);
return "edit-customer";
}
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String postEdit(@RequestParam("customerId") Integer customerId,
@ModelAttribute("customerAttribute") @Valid Customer customer, BindingResult result) {
if (result.hasErrors()) {
return "edit-customer";
}
customer.setCustomerId(customerId);
customerService.editCustomer(customer);
return "redirect:/test/customer/list";
Run Code Online (Sandbox Code Playgroud)
和两个jsp页面
edit-customer.jsp:
<body>
<h1>Edit Existing Customer</h1>
<c:url var="saveUrl" value="/test/customer/edit?customerId=${customerAttribute.customerId}" />
<form:form modelAttribute="customerAttribute" method="POST" action="${saveUrl}">
<table>
<tr>
<td><form:label path="customerId">Customer Id:</form:label></td>
<td><form:input path="customerId" disabled="true"/></td> …
Run Code Online (Sandbox Code Playgroud) java ×5
spring ×5
hibernate ×3
spring-mvc ×3
jsp ×2
annotations ×1
javabeans ×1
javascript ×1
methods ×1
orm ×1