日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

中國最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2

wkspring教程

Spring 靜態頁面例子

閱讀 (2195)

Spring 靜態頁面例子

下面的例子說明了如何使用 Spring MVC 框架來編寫一個簡單的基于 web 的應用程序,它可以在 <mvc:resources> 標簽的幫助下訪問靜態頁面和動態頁面。為了開始使用它,讓我們在恰當的位置使用 Eclipse IDE,然后按照下面的步驟使用 Spring 的 Web 框架來開發一個動態的基于表單的 Web 應用程序:

步驟 描述
1 創建一個名稱為 HelloWeb動態 Web 項目,并且在已創建的項目的 src 文件夾中創建一個包 com.tutorialspoint
2 將上面提到的 Spring 和其他庫拖拽到文件夾 WebContent/WEB-INF/lib 中。
3 com.tutorialspoint 包下創建一個 Java 類 WebController
4 WebContent/WEB-INF 文件夾下創建 Spring 的配置文件 Web.xmlHelloWeb-servlet.xml
5 WebContent/WEB-INF 文件夾下創建名稱為 jsp 的子文件夾。在這個子文件夾下創建一個視圖文件 index.jsp
6 WebContent/WEB-INF 文件夾下創建名稱為 pages 的子文件夾。在這個子文件夾下創建一個靜態文件 final.htm
7 最后一步是創建所有的源代碼和配置文件的內容,并導出該應用程序,正如下面解釋的一樣。

這里是 WebController.java 文件的內容:

package com.tutorialspoint;
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.htm";
   }
}

下面是 Spring Web 配置文件 web.xml 的內容

<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>Spring Page Redirection</display-name>

    <servlet>
        <servlet-name>HelloWeb</servlet-name>
        <servlet-class>
           org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloWeb</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

下面是另一個 Spring Web 配置文件 HelloWeb-servlet.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"
 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.tutorialspoint" />

    <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:annotation-driven/>

</beans>

在這里,<mvc:resources..../> 標簽被用來映射靜態頁面。 mapping 屬性必須是一個指定一個 http 請求的 URL 模式的 Ant 模式。 location 屬性必須指定一個或者多個具有包含圖片,樣式表,JavaScript 和其他靜態內容的靜態頁面的資源目錄位置。多個資源位置可以使用逗號分隔這些值的列表來被指定。

下面是 Spring 視圖文件 WEB-INF/jsp/index.jsp 的內容。這將是一個登陸頁面,這個頁面將發送一個請求來訪問 staticPage 的 service 方法,它將重定向這個請求到 WEB-INF/pages 文件夾中的一個可用的靜態頁面。

<%@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="/HelloWeb/staticPage">
<table>
    <tr>
    <td>
    <input type="submit" value="Get HTML Page"/>
    </td>
    </tr>
</table>  
</form:form>
</body>
</html>

下面是 Spring 視圖文件 WEB-INF/pages/final.htm 的內容。

<html>
<head>
    <title>Spring Static Page</title>
</head>
<body>

<h2>A simple HTML page</h2>

</body>
</html>

最后,下面是包含在你的 web 應用程序中的 Spring 和其他庫的列表。你僅僅需要將這些文件拖拽到 WebContent/WEB-INF/lib 文件夾中。

  • commons-logging-x.y.z.jar

  • org.springframework.asm-x.y.z.jar

  • org.springframework.beans-x.y.z.jar

  • org.springframework.context-x.y.z.jar

  • org.springframework.core-x.y.z.jar

  • org.springframework.expression-x.y.z.jar

  • org.springframework.web.servlet-x.y.z.jar

  • org.springframework.web-x.y.z.jar

  • spring-web.jar

一旦你完成了創建源代碼和配置文件后,導出你的應用程序。右鍵單擊你的應用程序,并且使用 Export > WAR File 選項,并且在 Tomcat 的 webapps 文件夾中保存你的 HelloWeb.war 文件。

現在啟動你的 Tomcat 服務器,并且確保你能夠使用標準的瀏覽器訪問 webapps 文件夾中的其他 web 頁面。現在嘗試訪問該 URL http://localhost:8080/HelloWeb/index。 如果你的 Spring Web 應用程序一切都正常,你應該看到下面的結果:

單擊 “Get HTML Page” 按鈕來訪問 staticPage 中的 service 方法中提到的一個靜態頁面。如果你的 Spring Web 應用程序一切都正常,你應該看到下面的結果:

關閉
程序員人生
主站蜘蛛池模板: 婷婷99狠狠躁天天躁中文字幕 | 在线视频a | 国产亚洲精品久久 | 久久国产精品视频免费看 | 久久大陆| 国产在线二区 | 免费一区二区视频 | 成人激情在线 | 欧美不卡 | 成年人黄色网址 | 黄色免费av | 欧美 日韩 亚洲 国产 | 7777视频| 色婷婷综合久久久中文字幕 | 午夜日韩免费视频 | 欧美黄色一级 | 中文字幕精品久久久乱码 | 男女av网站 | 亚洲91精品| 精品一区一区三区新区乱码 | 日韩在线视频观看 | 久久99精品久久久久久园产越南 | 久久久久久国产精品免费免费 | 亚洲精品免费看 | 亚洲区第一页 | 黄色av一级| 国内精品国产三级国产在线专 | 亚洲精品视频自拍 | 狠狠av| 在线中文字幕亚洲 | 国内精品一区二区三区 | 在线h片| 亚洲男女 | 挨操视频 | 国产精品66 | 99精品欧美一区二区三区 | 欧美中文字幕在线 | 亚洲综合在线免费 | 精品人伦一区二区三区蜜桃网站 | 国产精品日日做人人爱 | 国产va在线 |