在服务器端对客户端请求时行转发对其它的对象,如果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

最新文章

  1. Linux挂载卸载光盘&amp;实践
  2. mysql GROUP_CONCAT+ GROUP BY + substring_index获取分组的前几名
  3. delphi判断文件类型
  4. OneProxy使用手册--致力于打造透明的数据层
  5. Mysql避免全表扫描sql查询优化 .
  6. Linux 网卡驱动设备程序设计(1)
  7. 【原创】重绘winform的GroupBox
  8. python并发编程之多进程二
  9. C#语言中的修饰符
  10. 【POJ 1740】A New Stone Game
  11. postgresql,封装数据库语句时,查询报错。
  12. linux的基本操作(文本编辑工具vim)
  13. 7、LwIP协议规范翻译——网络接口
  14. MySQL学习(二) 数据类型
  15. Activiti工作流搭建---初始化数据库
  16. vmplayer桥接以及nat配置nginx
  17. 构建模式--Adapter模式(JAVA)
  18. Django 性能测试
  19. ubuntu安装LDAP
  20. FireFox 书签 缓存 路径设置

热门文章

  1. poj - 3686 The Windy&#39;s (KM算法)
  2. 通过继承Thread类来创建多线程 关键词 start
  3. Java的finally语句在try或catch中的return语句执行之后还是之前?
  4. SqlSugar最容易使用的ORM
  5. 【APUE】关于信号的一些常用函数
  6. Java中正则Matcher类的matches()、lookAt()和find()的差别
  7. 编写高质量代码:改善C#程序的157个建议
  8. 【Linux编程】进程终止和exit函数
  9. 修正iOS从照相机和相册中获取的图片 方向
  10. 目前使用过的各大厂商rtsp取流的url