spring中实现Controller接口的映射
来源:互联网 发布:网络接入服务商 编辑:程序博客网 时间:2024/05/21 17:11
21.1 新建一个SuccessController的类实现Controller接口;
package com.ask.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
//通过实现controller接口;
public class SuccessController implements Controller{
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
System.out.println("实现Controller接口");
return new ModelAndView("success");
}
}
21.2 在WEB-INF下新建一个views的文件,在views文件下新建一个success.jsp的文件;
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
success
</body>
</html>
22.3 在config文件下新建一个spring-mvc.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"
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-4.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.ask"/>
<bean id="successController" class="com.ask.controller.SuccessController"></bean>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="success.action">successController</prop>
</props>
</property>
<!--视图解析器-->
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
22.4 在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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>springMvc-1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 配置springmvc-->
<servlet>
<servlet-name>springmvc2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc2</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>
22.5 新建一个index.jsp页面;
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
welcom to ...
<a href="success.action">点击跳转</a>
</body>
</html>
- spring中实现Controller接口的映射
- 通过拦截器Interceptor实现Spring MVC中Controller接口访问信息的记录
- 通过拦截器Interceptor实现Spring MVC中Controller接口访问信息的记录
- Spring MVC(一)实现Controller接口的控制器
- 基于注解的Spring MVC的URL与Controller映射关系提取的实现分析
- 基于注解的Spring MVC的URL与Controller映射关系提取的实现分析
- 基于注解的Spring MVC的URL与Controller映射关系提取的实现分析
- Spring Mvc 表单数据与Controller中模型(Model)的映射
- spring mvc 获取所有的controller和url映射关系
- Spring MVC实例,使用Controller接口实现控制器
- Controller 接口及其实现
- spring MVC Controller 实现接口后,不能解析@Controller注解问题
- Spring MVC @Autowired、@Controller、@Service 的实现
- spring mvc中常用的几个controller
- spring mvc中常见的几个controller
- Spring MVC中基于注解的Controller
- Spring中Controller和RequestMapping的详解
- Spring中Controller和RequestMapping的详解
- 自定义图片浏览器
- mysql5.7.13安装(Linux)
- iOS7 edgesForExtendedLayout&automaticallyAdjustsScrollViewInsets
- Android实现推送方式解决方案 - 长连接+心跳机制(MQTT协议)
- freemarker路径问题
- spring中实现Controller接口的映射
- C语言求解线性方程组AX=b
- 找不到org.apache.http等类
- hadoop任务运行日志
- Android 自定义ViewGroup之实现FlowLayout-标签流容器
- SQL显示查询结果的前100条
- spring中的jdbc连接用户增删改查
- JAVA中subString的用法
- OpenJudge 1750: 全排列