springMVC环境搭建-4
来源:互联网 发布:js替换所有特殊字符 编辑:程序博客网 时间:2024/05/26 12:56
配置注解,实现页面跳转
新建包路径com.wf.login.controller(路径自定义),新建文件LoginController.java,
package com.wf.login.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;@Controller@RequestMapping("/login")public class LoginController {@RequestMapping("/tologinview")public ModelAndView toLoginView(){ModelAndView mav = new ModelAndView();//jsp页面路径前缀和后缀已经配置在springmvc.xml中了mav.setViewName("login/login");return mav;}}
在WEB-INF下新建jsp/login/login.jsp,作为跳转页面
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> This is my JSP page. <br> </body></html>
配置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:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "> <!-- 添加Controller遍历路径 --><!-- 模糊匹配 --> <context:component-scan base-package="com.wf.**.controller"></context:component-scan> <!-- 采用注解驱动方式配置适配器和映射器 --> <mvc:annotation-driven></mvc:annotation-driven> <!-- 添加视图解析器 --><!-- 配置路径的前缀和后缀,配置后可省略路径中的前后缀 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"></property> <property name="suffix" value=".jsp"></property> </bean></beans>
最后进行测试,启动项目,输入地址:http://localhost:8080/Dest/login/tologinview
进入login.jsp页面则表示配置成功了...
0 0
- springMVC环境搭建-4
- 【Spring实战4】10--搭建SpringMVC环境
- SpringMVC环境搭建
- SpringMVC环境搭建
- SpringMVC环境的搭建
- springmvc 入门环境搭建
- springMVC 4.1 环境搭建
- 搭建SpringMVC开发环境
- SpringMVC环境搭建
- springmvc环境的搭建
- springmvc 环境搭建
- springMVC环境搭建-1
- springMVC环境搭建-2
- springMVC环境搭建-3
- springMVC环境搭建-5
- springMVC环境搭建-6
- springMVC之环境搭建
- springmvc+maven环境搭建
- Channel Synchronization
- 【Redis源码学习】将长整数转换为字符串
- MyEclipse2015 Stable 2.0打JAR包,插件FatJar安装与使用
- spring+mybatis利用interceptor(plugin)兑现数据库读写分离
- linux 编辑保存文件命令
- springMVC环境搭建-4
- Java 多字符分割字符串(String.split() )
- IOS的小知识点补充
- equals和hashCode源码解析
- Throwable#initCause(Throwable) 方法
- 使用jazzyviewpager时,在19版本的…
- Fragment中的onCreateView方法什么…
- retrofit请求网络时,针对泛型解析…
- 读书笔记:android设计与实现第一…