发表于: 2018-03-22 20:02:23

1 527


今天完成的事情:

学习Java基础——泛型,容器类

 完成springMVC页面跳转

package com.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 = "/staticPage",method = RequestMethod.GET)
public String redirect() {
return "redirect:/pages/final.html";
   }

}

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app id="WebApp_ID" version="2.4"
        xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>Archetype Created Web Application</display-name>
 <servlet>
   <servlet-name>HelloWeb</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <!-- 设置配置文件的名称 和路径 -->
   <init-param>
     <param-name>WEB-INF/HelloWeb-servlet.xml</param-name>
     <param-value>classpath*:HelloWeb-servlet.xml</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
   <servlet-name>HelloWeb</servlet-name>
   <!--<url-pattern>*.html</url-pattern>-->
   <url-pattern>/</url-pattern>
 </servlet-mapping>
</web-app>
<!--<?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"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:component-scan base-package="com.controller" />

   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix" value="/WEB-INF/jsp/" />
       <property name="suffix" value=".jsp" />
   </bean>

   <mvc:resources mapping="/pages/**" location="/WEB-INF/pages/" />
   <!--<mvc:resources mapping="/**" location="/"/>-->
   <!-- 把标记了@Controller注解的类转换为bean -->
   <mvc:annotation-driven/>

</beans>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
   <title>Spring Landing Page</title>
</head>
<body>
<h2>Spring Landing Pag</h2>
<p>Click below button to get a simple HTML page</p>
<form:form method="GET" action="/staticPage">
<table>
       <tr>
           <td>
               <input type="submit" value="Get HTML Page"/>
           </td>
       </tr>
   </table>
</form:form>
</body>
</html>

明天计划的事情:

继续学习springMVC

 
遇到的问题:(


收获:

学会了springMVC跳转页面

容器类的描述

Java容器完整分类




返回列表 返回列表
评论

    分享到