春の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
@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());
}
その例外が発生する理由を教えてください。どんな助けもかなりのものです。前もって感謝します。
よろしく、ゴパル