zoukankan      html  css  js  c++  java
  • Spring MVC笔记(五) 页面重定向

    新建WEB工程pageRedirect,并引入springMVC相关jar包:

    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>pageRedirect</display-name>
      <servlet>
          <servlet-name>pageRedirect</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      </servlet>
      <servlet-mapping>
          <servlet-name>pageRedirect</servlet-name>
          <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>

    springMVC配置文件,pageRedirect-servlet.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="
       http://www.springframework.org/schema/beans     
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
        <context:component-scan base-package="com.young" />
    
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
    </beans>

    springMVC控制类,webController.java

    package com.young.saticpage.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    public class WebController {
      @RequestMapping(value = "/index", method = RequestMethod.GET)
      public String index() {
        return "index";
      }
    
      @RequestMapping(value = "/redirect", method = RequestMethod.GET)
      public String redirect() {
        return "redirect:finalPage";
      }
    
      @RequestMapping(value = "/finalPage", method = RequestMethod.GET)
      public String finalPage() {
        return "final";
      }
    }

    index.jsp和final.jsp如下:

    <%@ page contentType="text/html; charset=UTF-8"%>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <html>
    <head>
    <title>Spring Landing Page</title>
    </head>
    <body>
        <h2>SpringMVC 页面重定向</h2>
        <p>点击下面的按钮重定向到另外一个新的jsp</p>
        <form:form method="GET" action="/pageRedirect/redirect">
            <table>
                <tr>
                    <td><input type="submit" value="页面重定向" /></td>
                </tr>
            </table>
        </form:form>
    </body>
    </html>
    <%@ page contentType="text/html; charset=UTF-8"%>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <html>
    <head>
    <title>Spring Landing Page</title>
    </head>
    <body>
        <h2>页面重定向。。。。。。</h2>
    </body>
    </html>

    启动tomcat,并访问

  • 相关阅读:
    关于接口、抽象、普通类之间的选择
    对象与运行时内存
    maven
    ClassLoader
    股票数据调用示例代码php
    猫否股票策略十三篇-1.选股不重要,重在选时
    老枪的59条制胜法则
    今日趁利好出货又套人无数
    判断趋势的最佳指标---趋势大师(源码、主图、附图、说明、无未来、通达信)
    泰禾集团最近走势诡异,小心被机构戏耍了
  • 原文地址:https://www.cnblogs.com/weyoung1987/p/7979156.html
Copyright © 2011-2022 走看看