实现Spring MVC时出现状态404错误

时间:2017-11-04 11:32:32

标签: spring-mvc

我编写了我需要的所有内容并假设我导入了下面所有必需的弹簧罐是我的代码。使用角度框架的Js文件。登录对象已成功填充必填字段。但http://localhost:8081/MayuriSelection/registerUser.htm正在提供404。

$scope.Register = function(){
            $scope.register = {};
            $scope.register.usrName = $scope.usrName;
            $scope.register.email = $scope.email;
            $scope.register.pswd = $scope.pswd;
            $scope.register.confirmpswd = $scope.confirmpswd;
            console.log($scope.register);
            $http({
                method : "POST",
                url : "registerUser.htm",
                data : $scope.register
            }).then(function mySuccess(response) {
                $scope.myWelcome = response.data;
            }, function myError(response) {
                $scope.myWelcome = response.statusText;
            });

        }

Web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>MayuriSelection</display-name>

  <welcome-file-list>
    <welcome-file>login.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>


  <servlet>  
    <servlet-name>HelloCustomer</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <load-on-startup>1</load-on-startup>  
</servlet>

    <servlet-mapping>  
    <servlet-name>HelloCustomer</servlet-name>  
    <url-pattern>*.htm</url-pattern>  
    </servlet-mapping>

</web-app>

HelloCustomer-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:context = "http://www.springframework.org/schema/context"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- <context:component-scan base-package="com.mayuri.controller" /> -->

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/" />
        <property name="suffix" value=".html" />
    </bean>

</beans>

LoginController.java

/**
 * 
 */
/**
 * @author sagar reddy
 *
 */
package com.mayuri.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LoginController{

    @RequestMapping(value = "/registerUser.htm", method = RequestMethod.POST)
    public String login(){
        String message = "Hi Im here";
        System.out.println(message);
        return message;
    }
}

0 个答案:

没有答案