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>
本文介绍了一个使用Spring MVC框架实现的简单登录模块。该模块通过@Controller注解定义控制器类,并利用@RequestMapping注解指定请求路径。此外,还展示了如何在Spring配置文件中设置视图解析器及视图组件。

被折叠的 条评论
为什么被折叠?



