Springmvc4.1.5 不能跳转到Jsp页面;跪求大牛指导!

小样 发布于 2015/07/24 17:23
阅读 2K+
收藏 0
@RequestMapping(value="/t",method=RequestMethod.GET)
public String t(String params) {
    return "test/MyJsp";

}

debug调试提示:DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Written [test/MyJsp] as "text/html" using [org.springframework.http.converter.StringHttpMessageConverter@507d5ce]

无法跳转到MyJsp页面,直接输输出test/MyJsp;如图:


通过用ModelAndView方式可以跳转;

@RequestMapping(value="/t",method=RequestMethod.GET)
public ModelAndView t(String params) {

    ModelAndView mv = new ModelAndView();
    mv.setViewName("test/MyJsp");

    return mv;

}

Springmvc 配置xml,如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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.xsd">


<!-- 自动扫描bean,把作了注解的类转换为bean -->
<context:component-scan base-package="com.hj.lvmae">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Service" />
</context:component-scan>


<!-- 启动Spring MVC的注解功能 -->
<mvc:annotation-driven />


<bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="ignoreAcceptHeader" value="true" /> 
    <property name="defaultContentType" value="text/html" />
    <property name="favorParameter" value="false" />
    <property name="mediaTypes">
    <map>
        <entry key="html" value="text/html" />
        <entry key="json" value="application/json" />
        <entry key="atom" value="application/atom+xml" />
    </map>
    </property>
    <property name="viewResolvers">
        <list>
            <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
            <property name="contentType" value="text/html"/>
            <property name="order" value="0"></property>
            <property name="prefix" value="/WEB-INF/pages/" />
            <property name="suffix" value=".jsp" />
        </bean>
        </list>
    </property>
    <property name="defaultViews">
        <list>
        <bean
            class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
        </bean>
        </list>
    </property>
</bean>

</beans>

 跪求大牛指导;


加载中
0
沙漠草原狼

我也遇到这个问题,找了半天发现

web.xml

<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

注意,红色的地方,反斜杠后边没有*

返回顶部
顶部