0

我正在 Extjs 和 spring mvc 上开发演示项目。用户将输入一些详细信息,结果页面将显示用户详细信息。但是当我使用操作时:'/HelloWeb/addStudent.htm',发送请求它给了我 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>
4

2 回答 2

0

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

尝试添加.htm到映射:

@RequestMapping(value = "/addStudent.htm", method = RequestMethod.POST)
于 2013-10-23T13:17:55.513 回答
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) {
...
}
于 2013-10-23T13:27:26.770 回答