標籤: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請求轉寄小例子(轉載)