gpt4 book ai didi

java - 找不到 WebApplicationContext : no ContextLoaderListener

转载 作者:行者123 更新时间:2023-11-30 09:33:13 30 4
gpt4 key购买 nike

我是 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)

下面是我的代码细节:

web.xml:

 <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

spring-servlet.xml

<context:component-scan
base-package="com.paradigamatic.marchent.web.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/profile/"
p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView"/>

Controller 类:

    @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());

}

请告诉我为什么会出现该异常?任何帮助将不胜感激。提前致谢。

问候,戈帕尔

最佳答案

您需要将上下文加载监听器添加到您的 web.xml 中:

<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>

关于java - 找不到 WebApplicationContext : no ContextLoaderListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12331187/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com