Extjs spring 405 - 不支持请求方法'POST'

时间:2013-10-23 06:21:02

标签: spring-mvc extjs

我正在开发Extjs和spring mvc。上的演示项目,用户将输入一些细节,结果页面将显示用户详细信息。但是当我使用action:'/ HelloWeb / addStudent.htm'时,发送请求给出me 405 - 不支持请求方法'POST' 当我使用url:'/ HelloWeb / addStudent.htm然后它给404所请求的资源不可用

如何解决这个问题

这是我的index.jsp,有extjs代码

<script type="text/javascript">
        Ext.onReady(function(){
            Ext.QuickTips.init();
     var login = new Ext.FormPanel({ 
items:[{ 
            fieldLabel:'Name', 
            name:'Name', 
            allowBlank:false 
        },{ 
            fieldLabel:'age', 
            name:'age', 
            allowBlank:false 
        },{ 
            fieldLabel:'id', 
            name:'id', 
            allowBlank:false 
        }],


    buttons:[{ 
            text:'Submit',
            formBind: true,  

            handler:function(){ 
                login.getForm().submit({ 

                //url: '/HelloWeb/addStudent.htm' ,
                  action:'/HelloWeb/addStudent.htm',
                  method:'POST',
                  enctype: 'multipart/form-data',
                }); 

            }  
        }] 
    });

这是我的控制器

@RequestMapping(value = "/addStudent.htm", method = RequestMethod.POST)

 public String addStudent(@ModelAttribute("SpringWeb")Student student, 
  ModelMap model) {
  model.addAttribute("name", student.getName());
  model.addAttribute("age", student.getAge());
  model.addAttribute("id", student.getId());

  return "result";

}

这是我的Servlet.xml

<context:component-scan base-package="nil" />

                 

这是我的web.xml

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>HelloWeb</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>HelloWeb</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>

2 个答案:

答案 0 :(得分:0)

您将所有*.htm请求映射到Spring,但控制器中的请求映射设置为/addStudent - 没有.htm后缀

尝试将.htm添加到映射中:

@RequestMapping(value = "/addStudent.htm", method = RequestMethod.POST)

答案 1 :(得分:0)

表单操作是:

action:'/HelloWeb/addStudent.htm'

将请求发布到/addStudent.htm。但addStudent方法已映射到/addStudent

@RequestMapping(value = "/addStudent", method = RequestMethod.POST)

要使其有效,请将value注释@RequestMapping参数的值更改为:

@RequestMapping(value = "/addStudent.htm", method = RequestMethod.POST)
public String addStudent(@ModelAttribute("SpringWeb")Student student, 
  ModelMap model) {
...
}