Java 在实践书中学习Spring和Spring,在执行recipe 4.1时获取异常org.apache.jasper.jaspereException:
我正在使用《实践中的春天》一书来学习春天,我正在用配方4.1的例子来挑战自己。示例的代码如下所示 我得到这个错误:Java 在实践书中学习Spring和Spring,在执行recipe 4.1时获取异常org.apache.jasper.jaspereException:,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我正在使用《实践中的春天》一书来学习春天,我正在用配方4.1的例子来挑战自己。示例的代码如下所示 我得到这个错误: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [97] in the generated java file: [C:\Users\username\workspace\.metadata\.plugins\org.eclipse.ws
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [97] in the generated java file: [C:\Users\username\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\com.springinpractice.04_02\org\apache\jsp\WEB_002dINF\jsp\users\registrationForm_jsp.java]
The method getDispatcherType() is undefined for the type HttpServletRequest
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:198)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:450)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:580)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
我不知道这是否是访问错误的http地址的问题,我在访问这个地址时遇到了错误
这是我的XML配置,与从GitHub下载的示例相同:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
<param-name>appName</param-name>
<param-value>SiP University</param-value>
</context-param>
<context-param>
<param-name>recipe</param-name>
<param-value>4.2</param-value>
</context-param>
<context-param>
<param-name>aboutThisRecipe</param-name>
<param-value><![CDATA[
<p>In recipe 4.2 we replace hardcoded strings in the JSPs with externalized strings. This supports
internationalization. It also supports a separation of duties between developers and, for example, user
experience specialists.</p>
]]></param-value>
</context-param>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring/beans-web.xml
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
beans-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
========================================================================================================================
beans-web.xml
Copyright (c) 2013 Manning Publications Co.
Willie Wheeler (willie.wheeler@gmail.com)
Book: http://manning.com/wheeler/
Blog: http://springinpractice.com/
Code: https://github.com/springinpractice
========================================================================================================================
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<mvc:annotation-driven />
<mvc:default-servlet-handler />
<mvc:view-controller path="/home.html" view-name="extras/home" />
<mvc:view-controller path="/users/registration_ok.html" view-name="users/registrationOk" />
<context:component-scan base-package="com.springinpractice.ch04.web" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basename="classpath:/spring/messages" />
</beans>
非常感谢你的帮助。我知道这是另一个新手问题,但我无法通过查看其他问题找到解决方案。我回答自己的问题,因为我最终找到了解决方案,因此如果其他人再次发现此问题,则会出现以下情况: 由于问题的错误,WebApp没有直接在tomcatv8.0中运行。在TomcatV6.0中,出现错误,无法从JAR文件中读取TLD“META-INF/c.TLD”
解决方案是在Jetty中运行它,然后指向该点的正确地址是您在使用tomcat吗?如果是这样,servlet api jar和tomcat的版本是什么?您好,我使用的是tomcat v8.0,据我所知,这本书中的servlet api的作者使用的是自己的pack jar com.springinpractice.deps-web。我使用的是GitHub的同一版本,所以我认为没有代码错误,或者我访问了错误的URL地址