我是Spring MVC的新手。所以我开始使用非常简单的MVC应用程序。在这个应用程序中,我正在尝试提交登录表单,但它是givivng下面提到的错误:
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>
弹簧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
@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());
}
请告诉我为什么我会得到这个例外?任何帮助都会很明显。提前谢谢。
此致 戈帕尔
答案 0 :(得分:2)
您需要向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>
答案 1 :(得分:0)
您使用的是什么版本的Spring MVC?使用源代码检查堆栈跟踪。如果您使用Maven,您的IDE应该能够将堆栈跟踪线与jar源代码链接起来。