Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未找到WebApplicationContext:没有ContextLoaderListener_Java_Spring_Spring Mvc - Fatal编程技术网

Java 未找到WebApplicationContext:没有ContextLoaderListener

Java 未找到WebApplicationContext:没有ContextLoaderListener,java,spring,spring-mvc,Java,Spring,Spring Mvc,我是spring MVC的新手。所以我从非常简单的MVC应用程序开始。在此应用程序中,我试图提交登录表单,但出现以下错误: SEVERE: Servlet.service() for servlet [jsp] in context with path [/My-project] threw exception [An exception occurred processing JSP page /profile/logon.jsp at line 8 5: </head>

我是spring MVC的新手。所以我从非常简单的MVC应用程序开始。在此应用程序中,我试图提交登录表单,但出现以下错误:

SEVERE: Servlet.service() for servlet [jsp] in context with path [/My-project] threw exception [An exception occurred processing JSP page /profile/logon.jsp at line 8

    5: </head>
    6: <body>
    7: <h2>USER Login</h2>
    8: <form:form method="post" action="addlogon.jsp">
    9: 
    10:     <table>
    11:     <tr>


    Stacktrace:] with root cause
    java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
        at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:81)
        at org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:81)
        at org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:219)
        at org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:74)
        at org.springframework.web.servlet.support.JspAwareRequestContext.<init>(JspAwareRequestContext.java:48)
        at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:75)
        at org.apache.jsp.profile.logon_jsp._jspx_meth_form_005fform_005f0(logon_jsp.java:110)
        at org.apache.jsp.profile.logon_jsp._jspService(logon_jsp.java:79)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
        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:987)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1815)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
请告诉我为什么我会得到那个例外?任何帮助都是值得的。提前谢谢

问候,,
Gopal

您需要向web.xml添加上下文加载侦听器:

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

上下文配置位置
/WEB-INF/yourApplicationContext.xml
听众:

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

org.springframework.web.context.ContextLoaderListener

您使用的是哪个版本的Spring MVC?使用源代码检查堆栈跟踪。如果使用Maven,IDE应该能够将堆栈跟踪行与jar源代码链接起来。

首先尝试清理服务器。如果这没有帮助,那么请发布您的web.xml以及您使用的tomcat版本。添加了一些代码。现在请您检查一下。但是我的应用程序到目前为止不需要ApplicationContext.xml。还有一个教程在我的机器上运行良好。下面是链接:从堆栈跟踪来看,它似乎是需要ContextLoaderListener的SpringJSP标记。你刚开始使用标签库吗?这里也有同样的问题。当我使用SpringJSP标记表单时,我遇到了这个错误。没有它,我不会有任何错误。请注意,我在应用程序中设置了app-servlet.xml和ContextLoaderListener。
    @Controller
@SessionAttributes
public class LogonController  {

    @RequestMapping(value="/profile/addlogon", method = RequestMethod.POST)
    public String addlogon(@ModelAttribute("userlogon") UserLogon userlogon, BindingResult result){

        String user=userlogon.getUsername();
        String user1=userlogon.getPassword();
            return "redirect:logon.jsp";
        }

@RequestMapping(value="/profile/logon", method = RequestMethod.GET)
public ModelAndView handalRequestInternal(HttpServletRequest req,HttpServletResponse res)
{

    System.out.println("I am in controller");
    return new ModelAndView("logon", "command", new UserLogon());

}
<context-param>
    <param-name>contextConfigLocation</param-name>        
<param-value>/WEB-INF/yourApplicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>