Spring mvc采用配置的方式前转页面

 Controller

package com.tibco.gse.web.cms;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class Login {

	@RequestMapping(value = "/cms/login", method = RequestMethod.GET)
	public String login(
			@RequestParam(required = false, value = "error") String error,
			Model model) {
		model.addAttribute("error", error);

		return "forward:/jsp/login.jsp";

	}

}

 

 

applicationContext-mvc.xml

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

	<annotation-driven />
	<default-servlet-handler />
	
	 <beans:bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

     <beans:bean class="org.springframework.web.servlet.view.XmlViewResolver" >
          <beans:property name="location">
              <beans:value>classpath:spring/spring-views.xml</beans:value>
          </beans:property>
     </beans:bean>
	
	 <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></beans:property>
        <beans:property name="prefix" value="/jsp/"></beans:property>
        <beans:property name="suffix" value=".jsp"></beans:property>        
    </beans:bean>
	

</beans:beans>

 

 spring-views.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns="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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
         
         <beans:bean id="login"
	          class="org.springframework.web.servlet.view.JstlView">
	        <beans:property name="url" value="/cms/scheduler" />
	    </beans:bean>
	    
	    <beans:bean id="scheduler"
	          class="org.springframework.web.servlet.view.JstlView">
	        <beans:property name="url" value="/jsp/scheduler/scheduler.jsp" />
	    </beans:bean>
         
</beans:beans>

 

猜你喜欢

转载自quqtalk.iteye.com/blog/2073563
今日推荐