多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

中國(guó)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2

wkspring教程

Spring 頁(yè)面重定向例子

閱讀 (2175)

Spring 頁(yè)面重定向例子

下面的例子說(shuō)明了如何編寫(xiě)一個(gè)簡(jiǎn)單的基于 web 的應(yīng)用程序,它利用重定向來(lái)傳送一個(gè) http 請(qǐng)求到另一個(gè)頁(yè)面中。為了開(kāi)始使用它,讓我們?cè)谇‘?dāng)?shù)奈恢檬褂?Eclipse IDE,然后按照下面的步驟使用 Spring 的 Web 框架來(lái)開(kāi)發(fā)一個(gè)動(dòng)態(tài)的基于表單的 Web 應(yīng)用程序:

步驟 描述
1 創(chuàng)建一個(gè)名稱(chēng)為 HelloWeb動(dòng)態(tài) Web 項(xiàng)目,并且在已創(chuàng)建的項(xiàng)目的 src 文件夾中創(chuàng)建一個(gè)包 com.tutorialspoint。
2 將上面提到的 Spring 和其他庫(kù)拖拽到文件夾 WebContent/WEB-INF/lib 中。
3 com.tutorialspoint 包下創(chuàng)建一個(gè) Java 類(lèi) WebController
4 WebContent/WEB-INF 文件夾下創(chuàng)建 Spring 的配置文件 Web.xmlHelloWeb-servlet.xml。
5 WebContent/WEB-INF 文件夾下創(chuàng)建名稱(chēng)為 jsp 的子文件夾。在這個(gè)子文件夾下創(chuàng)建視圖文件 index.jspfinal.jsp。
6 最后一步是創(chuàng)建所有的源代碼和配置文件的內(nèi)容,并導(dǎo)出該應(yīng)用程序,正如下面解釋的一樣。

這里是 WebController.java 文件的內(nèi)容:

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 = "/redirect", method = RequestMethod.GET)
   public String redirect() {     
      return "redirect:finalPage";
   }   
   @RequestMapping(value = "/finalPage", method = RequestMethod.GET)
   public String finalPage() {     
      return "final";
   }
}

下面是 Spring Web 配置文件 web.xml 的內(nèi)容

<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>

下面是另一個(gè) Spring Web 配置文件 HelloWeb-servlet.xml 的內(nèi)容

<?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"
   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">

    <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>
</beans>

下面是 Spring 視圖文件 index.jsp 文件的內(nèi)容。這將是一個(gè)登陸頁(yè)面,這個(gè)頁(yè)面將發(fā)送一個(gè)請(qǐng)求來(lái)訪問(wèn)重定向 service 方法,該方法將把這個(gè)請(qǐng)求重定向到另一個(gè) service 方法中,最后將顯示 final.jsp 頁(yè)面。

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
    <title>Spring Page Redirection</title>
</head>
<body>
<h2>Spring Page Redirection</h2>
<p>Click below button to redirect the result to new page</p>
<form:form method="GET" action="/HelloWeb/redirect">
<table>
    <tr>
    <td>
    <input type="submit" value="Redirect Page"/>
    </td>
    </tr>
</table>  
</form:form>
</body>
</html>

下面是 Spring 視圖文件 final.jsp 的內(nèi)容。這是最終的重定向頁(yè)面。

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
    <title>Spring Page Redirection</title>
</head>
<body>

<h2>Redirected Page</h2>

</body>
</html>

最后,下面是包含在你的 web 應(yīng)用程序中的 Spring 和其他庫(kù)的列表。你僅僅需要將這些文件拖拽到 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

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

現(xiàn)在啟動(dòng)你的 Tomcat 服務(wù)器,并且確保你能夠使用標(biāo)準(zhǔn)的瀏覽器訪問(wèn) webapps 文件夾中的其他 web 頁(yè)面?,F(xiàn)在嘗試訪問(wèn)該 URL http://localhost:8080/HelloWeb/index。如果你的 Spring Web 應(yīng)用程序一切都正常,你應(yīng)該看到下面的結(jié)果:

現(xiàn)在單擊 “Redirect Page” 按鈕來(lái)提交表單,并且得到最終的重定向頁(yè)面。如果你的 Spring Web 應(yīng)用程序一切都正常,你應(yīng)該看到下面的結(jié)果:

關(guān)閉
程序員人生
主站蜘蛛池模板: 国产日韩亚洲 | 波多野结衣久久高清免费 | 91亚洲综合 | 欧美精品黑人性xxxx | 在线观看日本永久免费视频 | 91福利视频免费观看 | 欧美一卡二卡3卡4卡无卡免费 | 多人做人爱视频在线观看 | 中文字幕亚洲第一 | 国产v欧美v日本v精品 | 国产毛片片精品天天看视频 | 校园春色亚洲 | 国产精品久久久久久一区二区三区 | 国产成人久久久精品一区二区三区 | 亚洲国产情侣一区二区三区 | 日韩欧美精品 | 一区二区三区免费视频网站 | 黄色aa毛片 | 欧美伦理三级在线播放影院 | 欧美孕交videosfree巨大 | 国产高清吃奶成免费视频网站 | 欧美精品1区2区 | 日本天堂视频 | 俺去啦最新官网 | 尤物视频在线 | 亚洲欧美a| 日韩在线a视频免费播放 | 第一页在线观看 | 亚洲经典在线观看 | 香蕉狠狠再啪线视频 | 亚洲第一天堂 | 亚洲成a人片77777kkkk | 国产偷v国产偷v亚洲高清 | 亚洲一本之道在线观看不卡 | 国产精品久久精品 | 伊人成人久久 | 黑人网址| 多人做人爱视频在线观看 | 亚洲区一区 | 一区二区在线观看视频 | a爱爱视频|