javax.servlet.ServletException - 无法解析具有名称的视图

时间:2014-12-10 10:37:54

标签: java spring jsp servlets

我在Spring开发控制器。 这是我的控制器代码:

@Controller
@RequestMapping("/consumer")
public class ConsumerController extends AbstractController {
    public ConsumerController() {
        super();
    }

    //Services
    @Autowired
    ConsumerService consumerService;
    //Constructors


    // Lista de consumidores ---------------------------------------------------------------        
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ModelAndView listConsumers() {
        ModelAndView result = new ModelAndView("customer/list");
        Collection<Consumer> consumers = consumerService.getAllConsumer();
        result.addObject("customers",consumers);
        result.addObject("customerType", "Consumer");
        result.addObject("requestURI","consumer/list.do");
        return result;
        }
}

现在,这是我的tiles.xml

<tiles-definitions>

    <definition name="consumer/list" extends="master.page"> 
        <put-attribute name="title" value="List of consumers" />
        <put-attribute name="body" value="/views/customer/list.jsp" />
    </definition>

    <definition name="supplier/list" extends="master.page"> 
        <put-attribute name="title" value="List of suppliers" />
        <put-attribute name="body" value="/views/customer/list.jsp" />
    </definition>

    <definition name="register" extends="master.page">  
        <put-attribute name="title" value="Register" />
        <put-attribute name="body" value="/views/customer/register.jsp" />
    </definition>   

</tiles-definitions>

这是我想在我的应用程序中显示的观点:

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="display" uri="http://displaytag.sf.net"%>

<display:table name="customers" id="row" pagesize="3" requestURI="${requestURI}" class="displaytag">

    <spring:message code="customer.name" var="cname" />
    <display:column title="${cname)" property="name" sortable="true" />

    <spring:message code="customer.surname" var="csurname" />
    <display:column title="${csurname}" property="surname" sortable="true"/>

    <spring:message code="customer.email" var="cemail" />
    <display:column title="${cemail}" property="email"/>

    <spring:message code="customer.ticker" var="cticker" />
    <display:column title="${cticker}" property="ticker"/>

    <display:column>
            <jstl:if test="${customerType == 'Supplier'}">
                    <a href="item/list.do?supplierId=${row.id}">
                        <spring:message code="item.show.item" />
                    </a>
            </jstl:if>  
    </display:column>
</display:table>

当我尝试访问&#39; /consumer/list.do /&#39;或者&#39; supplier / list.do&#39;,Eclipse向我展示了这个例外:

SEVERE: Servlet.service() for servlet [Acme-BrokerServlet] in context with path [/Acme-Broker] threw exception [Could not resolve view with name 'customer/list' in servlet with name 'Acme-BrokerServlet'] with root cause
javax.servlet.ServletException: Could not resolve view with name 'customer/list' in servlet with name 'Acme-BrokerServlet'
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

我尝试了很多想法,更改了网址,审核了我的代码...... 我无法知道发生了什么,无论如何,我会一直试图解决这个问题。 谢谢你的关注。

2 个答案:

答案 0 :(得分:0)

您将客户/列表作为视图ModelAndView result = new ModelAndView("customer/list");

返回

但是你的瓷砖上没有瓷砖。

你只有

"consumer/list"
"supplier/list"

答案 1 :(得分:0)

检查一下 - 上述问题有三种解决方案。将新依赖项添加到pom对我有用。

http://www.javavids.com/video/spring-web-app-tutorial-extras-apache-tiles-causes-server-error.html