springmvc页面跳转报错,什么原因

严重: Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.util.WebUtils.getResponseEncodedHtmlEscape(Ljavax/servlet/ServletContext;)Ljava/lang/Boolean;] with root cause
java.lang.NoSuchMethodError: org.springframework.web.util.WebUtils.getResponseEncodedHtmlEscape(Ljavax/servlet/ServletContext;)Ljava/lang/Boolean;
at org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:268)
at org.springframework.web.servlet.support.RequestContext.(RequestContext.java:169)
at org.springframework.web.servlet.view.JstlView.exposeHelpers(JstlView.java:135)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:142)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Spring MVC Application</display-name>


    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>


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

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
 <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

    <mvc:annotation-driven/>
    <mvc:resources location="/static/" mapping="/static/**"/>
    <!--自动扫描-->
    <context:component-scan base-package="com.lanyus"/>

    <!-- 引入配置文件 -->
    <!--<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">-->
        <!--<property name="location" value="classpath*:paramConfig.properties" />-->
    <!--</bean>-->

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:com/lanyus/*/mapping/*.xml"/>
    </bean>
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.lanyus.*.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8"/>
        <property name="username" value="root"/>
        <property name="password" value="roof"/>
        <property name="maxActive" value="100"/>
        <property name="maxIdle" value="10"/>
        <property name="minIdle" value="0"/>
        <property name="defaultAutoCommit" value="false"/>
    </bean>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
        <property name="contentType" value="text/html" />
        <property name="prefix"><value>/WEB-INF/page/</value></property>
        <property name="suffix"><value>.jsp</value></property>
    </bean>

    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory"/>
        <constructor-arg index="1" value="BATCH"/>
    </bean>

</beans>

 package com.lanyus.user.controller;

import com.lanyus.user.entity.User;
import com.lanyus.user.service.UserService;
import com.lanyus.core.Constant;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
//@Responsebody 后返回结果不会被解析为跳转路径,而是直接写入HTTP 响应正文中
@Controller
@RequestMapping("/spring/user")
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping("home")
    public String hot(){
        return "main";
    }

}

7个回答

是版本问题,旧版本没有org.springframework.web.util.WebUtils.getResponseEncodedHtmlEscape方法.(4.1.2及以上版本才有)
/**
* Return whether response encoding should be used when HTML escaping characters,
* thus only escaping XML markup significant characters with UTF-* encodings.
* This option is enabled for the web application with a ServletContext param,
* i.e. the value of the "responseEncodedHtmlEscape" context-param in {@code web.xml}
* (if any).
*

This method differentiates between no param specified at all and
* an actual boolean value specified, allowing to have a context-specific
* default in case of no setting at the global level.
* @param servletContext the servlet context of the web application
* @return whether response encoding is to be used for HTML escaping
* ({@code null} = no explicit default)
* @since 4.1.2
*/
public static Boolean getResponseEncodedHtmlEscape(ServletContext servletContext) {
if (servletContext == null) {
return null;
}
String param = servletContext.getInitParameter(RESPONSE_ENCODED_HTML_ESCAPE_CONTEXT_PARAM);
return (StringUtils.hasText(param) ? Boolean.valueOf(param) : null);
}

qq_36419312
小悬
2 年多之前 回复

终于把问题处理了,既不是control的问题,也不是配置文件的问题,是spring的jar包有问题,换了jar就跳转正常了

control出错,贴mvc配置文件无法解决你的问题,贴control类,web.xml、bean.xml文件

qq_36419312
小悬 回复qq_33330032: 我处理了,control没问题,是用的spring的jar包有问题
2 年多之前 回复
qq_36419312
小悬 回复qq_33330032: control问题出在哪
2 年多之前 回复
qq_33330032
qq_33330032 control有问题
2 年多之前 回复
qq_36419312
小悬 上面是分别是web.xml、control、mvc配置文件,就这一个配置文件
2 年多之前 回复

哪位大神能看出问题具体在哪?

Path路径错误 检查路径中是否包含中文字符 有要去掉

qq_36419312
小悬 是版本的问题
2 年多之前 回复

control出错,配置文件出错,详细的看一遍配置文件

qq_36419312
小悬 control、配置文件都没错,是用的spring的jar包有问题,换了就好了
2 年多之前 回复
qq_36419312
小悬 上面是所有的配置文件,哪里出问题了
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐