首页 新闻 会员 周边 捐助

突然发现controller 请求,当返回值为空的时候,仍然跳转到页面

0
悬赏园豆:15 [已解决问题] 解决于 2017-05-03 21:03

Controller的方法

@Controller
public class TestController {

    @RequestMapping(value = "test.do")
    public void test1() {

    }
}

这边没有返回值,但是我在页面输入 http://localhost:8080/test.do 

他还是会跳转到 WEB-INF下的test.jsp页面

web.xml 配置

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


    <display-name>Archetype Created Web Application</display-name>


    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-context.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>

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


</web-app>

spring-servlet.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: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">

    <mvc:resources mapping="/resources/**" location="/resources/"/>

    <context:annotation-config/>

   <!-- <mvc:default-servlet-handler/>-->

    <mvc:annotation-driven/>

    <context:component-scan base-package="com.anhoo"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

 

求解答

大园子的主页 大园子 | 初学一级 | 园豆:37
提问于:2017-05-03 15:07
< >
分享
最佳答案
1

你可以看下DispatcherServlet中有提到一个类RequestToViewNameTranslator,当返回为空时,这个对象会对request进行处理,将uri映射为view

收获园豆:15
如切如磋,如琢如磨 | 菜鸟二级 |园豆:216 | 2017-05-03 17:08

好的,谢谢

大园子 | 园豆:37 (初学一级) | 2017-05-03 21:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册