jsp請求轉寄小例子(轉載)

來源:互聯網
上載者:User

標籤:username   返回   get   http   pat   val   hive   伺服器   ons   

在伺服器端對用戶端請求時行轉寄對其它的對象,如果jsp網頁或Servlet

用三個 jsp網頁來示範轉寄:

forword1.jsp, 用來提交表單, 將表單內容提交給 forwrod2.jsp,  forward1.jsp代碼如下:

<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>Forward1</title>    </head>    <body>        <h1>Forward1</h1>        <form action="forward2.jsp">            姓名: <input type="text" name="username"/>            <input type="submit" name="submit" value="提交"/>                    </form>    </body></html>

forward2.jsp 功能是將用戶端的請求的內容轉寄給forward3.jsp, 然後將網頁forward3.jsp返回給用戶端, forward2.jsp的代碼如下:

<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>Forward2</title>    </head>    <body>        <h1>Forward2</h1>        <%            RequestDispatcher rd = request.getRequestDispatcher("forward3.jsp");            rd.forward(request, response);                %>    </body></html>

forward3.jsp是用來返回給用戶端的, 代碼如下:

<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>Forward3</title>    </head>    <body>        <h1>Forward3</h1>                <%               String username = request.getParameter("username");        %>                使用者名稱為: <%=username %>            </body></html>

*轉載自http://www.cnblogs.com/shanhaiyang/archive/2011/07/30/2121842.html

jsp請求轉寄小例子(轉載)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.