0

This question has been asked previously as well but it went unanswered for me. So posting it. Please help.

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>Angular</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <servlet>
        <servlet-name>Spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
         <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/XmlViewResolver.xml</param-value>
        </init-param> 
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Spring</servlet-name>
        <url-pattern>rest/*</url-pattern>
    </servlet-mapping> 


  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/Spring-servlet.xml

        </param-value>
    </context-param> 
     <!-- <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener> -->

    <session-config>
  <session-timeout>30</session-timeout>
  </session-config>
</web-app>

XmlViewResolver.xml

<context:annotation-config />
            <context:component-scan base-package="main.java.com.controller" use-default-filters="false">
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
        </context:component-scan>
        <mvc:annotation-driven />
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/views" />
    <property name="suffix" value=".html" />
    <property name="order" value="1" />
  </bean>

Spring-servlet.xml

    <context:annotation-config />
        <context:component-scan base-package="main.java.com.controller" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
        <mvc:annotation-driven />
        <tx:annotation-driven transaction-manager="transactionManager"/>


inside Indexcontroller.js


     $scope.login = function()
            {
                 $http.post('rest/login', $scope.loginDto).success(function(data)
                            {
                     alert('success');
                            }).error(function() 
                            {
                                alert('error while delete file.');
                            });
            };

Indexcontroller.java

    @Controller
    public class IndexController {
    @RequestMapping(value = "/login", method = RequestMethod.POST, consumes="application/json", produces="application/json")
        public  @ResponseBody LoginDto login(@RequestBody  LoginDto loginDto, HttpServletRequest req)  
        {
            System.out.println(loginDto.getUserName()+" :::: "+loginDto.getPassword());
            return loginDto;
        }
    }
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
Supriya
  • 21
  • 3
  • Read [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). – georgeawg Mar 19 '17 at 18:54
  • Also see [Why are angular $http success/error methods deprecated? Removed from v1.6?](http://stackoverflow.com/questions/35329384/why-are-angular-http-success-error-methods-deprecated-removed-from-v1-6/35331339#35331339). – georgeawg Mar 19 '17 at 18:56
  • Hey George... thanks for that excellent post. I'll take care of that. As of now, i wanted ppl here to figure out if i am missing something in configuration file because as per my check controller is not getting loaded so probably there is issue with spring config in specifying controller/mapping config. – Supriya Mar 20 '17 at 08:19

0 Answers0