未找到弹簧控制器

时间:2016-08-16 15:22:05

标签: java angularjs spring-mvc

我无法解决这个问题我是春天新手所以它可能很傻但我的角度帖请求不与java弹簧控制器通信...

我的角度代码..

function check($scope,$http){
 $scope.go = function (){
      var go = $http({
          method:'POST',
      url:'/addentry/pp',
  data : $scope.abc
  })  ;
};

我的添加条目类......

package all;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
*
* @author om
*/
@Controller
@RequestMapping("/addentry")
public class addentry {
@RequestMapping(value = "/addentry/pp" ,method = RequestMethod.POST)
public @ResponseBody String reply(@RequestParam("name") String        name,@RequestParam("pass") String pass){
    return "hello";
}     
}

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>dispatcher</servlet-name>
       <servlet-    class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
   </servlet-mapping>
   <session-config>
      <session-timeout>
         30
    </session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>home/index.html</welcome-file>
    </welcome-file-list>
    </web-app>

servlet的dispatcher.xml

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

  <!--
  Most controllers will use the ControllerClassNameHandlerMapping above, but
  for the index controller we are using ParameterizableViewController, so we must
  define an explicit mapping for it.
  -->
  <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
     <property name="mappings">
        <props>
            <prop key="index.htm">indexController</prop>
        </props>
    </property>
</bean>

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

<!--
The index controller.
-->
<bean name="indexController"
      class="org.springframework.web.servlet.mvc.ParameterizableViewController"
      p:viewName="index" />

但我收到404错误....(addentry / pp not found)

1 个答案:

答案 0 :(得分:0)

您的@RequestMapping注释错误。您已使用@RequestMapping注释了控制器和方法(这很好),但/addentry定义了两次。 Spring将回复/addentry/addentry/pp

从控制器(类定义)或方法中删除/ addentry。

相关问题