小编dli*_*x90的帖子

HTTP状态405 - 不支持请求方法"POST"(Spring MVC)

我得到这个错误: 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)

javascript java methods spring hibernate

24
推荐指数
4
解决办法
11万
查看次数

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为'customerService'的bean

我需要帮助修复我在尝试将我的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)

java spring hibernate spring-mvc javabeans

13
推荐指数
1
解决办法
17万
查看次数

如何在Spring MVC中填充下拉框

我一直试图找出如何填充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)

java spring jsp spring-mvc drop-down-menu

11
推荐指数
3
解决办法
5万
查看次数

嵌套异常是java.lang.IllegalStateException:无法将类型[java.lang.String]的值转换为所需类型

我尝试提交表单时收到以下验证错误.使用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)

两个表之间的关系是几个 …

java orm spring annotations hibernate

6
推荐指数
1
解决办法
1万
查看次数

@RequestParam为null(Spring MVC)

我正在尝试向我的网络应用添加编辑功能,但我在使用时遇到了一些问题@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 model-view-controller spring jsp spring-mvc

1
推荐指数
1
解决办法
7792
查看次数