Spring MVC返回响应,但不呈现视图

时间:2015-11-01 06:50:18

标签: html angularjs jsp spring-mvc

我无法在从html页面发出请求时呈现视图。以下是详细信息: 1)controllers.js文件

$scope.getAllApps = function() {
            $scope.applications = [];
            var getAllApplicationsUrl = _appContext+"/application/get";
            $http.get(getAllApplicationsUrl);
    }

2)ApplicationController.java文件

@RequestMapping(value="/get")
    public String getAllApplications() throws ApplicationException {
            throw new ApplicationException("Testing error page...");
            //return applicationService.getAllApplications();
    }

    @ExceptionHandler(value = Exception.class)
    public static ModelAndView redirectOnException(Exception e) {
            ModelAndView mv = new ModelAndView("error");
            mv.addObject("errMsg", e.getMessage());
            return mv;
    }

3)在DEBUG模式下的StackTrace:

    DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'error'; URL [/WEB-INF/views/error.jsp]] in DispatcherServlet with name 'appServlet'
DEBUG: org.springframework.web.servlet.view.JstlView - Added model object 'errMsg' of type [java.lang.String] to request in view with name 'error'
DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/error.jsp] in InternalResourceView 'error'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/ams/application/get]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /application/get
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public java.lang.String com.sarvesh.ams.controller.ApplicationController.getAllApplications() throws com.sarvesh.ams.exceptions.ApplicationException]
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'applicationController'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/ams/application/get] is: -1
DEBUG: org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.sarvesh.ams.controller.ApplicationController.getAllApplications() throws com.sarvesh.ams.exceptions.ApplicationException]: com.sarvesh.ams.exceptions.ApplicationException: Testing error page...
DEBUG: org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Invoking @ExceptionHandler method: public static org.springframework.web.servlet.ModelAndView com.sarvesh.ams.controller.ApplicationController.redirectOnException(java.lang.Exception)
DEBUG: org.springframework.web.servlet.DispatcherServlet - Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'error'; model is {errMsg=Testing error page...}
com.sarvesh.ams.exceptions.ApplicationException: Testing error page...
        at com.sarvesh.ams.controller.ApplicationController.getAllApplications(ApplicationController.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)
DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'error'; URL [/WEB-INF/views/error.jsp]] in DispatcherServlet with name 'appServlet'
DEBUG: org.springframework.web.servlet.view.JstlView - Added model object 'errMsg' of type [java.lang.String] to request in view with name 'error'
DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/error.jsp] in InternalResourceView 'error'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request

如您所见,视图已成功返回,但未呈现error.jsp页面。我可以在chrome调试器中看到响应页面已返回,但它没有呈现。

当我从浏览器直接获取请求时,它可以工作(呈现error.jsp)。但是,当我点击'applicationForm.html'页面上的'获取应用'按钮时,不会呈现error.jsp(但是响应是由spring控制器发送的)。

screenshot of view not rendering from html page

screenshot of view rendered from normal get request in browser

提前致谢...

0 个答案:

没有答案