jsp请求转发小例子(转载)
2024-09-08 16:30:28
在服务器端对客户端请求时行转发对其它的对象,如果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
最新文章
- Linux挂载卸载光盘&;实践
- mysql GROUP_CONCAT+ GROUP BY + substring_index获取分组的前几名
- delphi判断文件类型
- OneProxy使用手册--致力于打造透明的数据层
- Mysql避免全表扫描sql查询优化 .
- Linux 网卡驱动设备程序设计(1)
- 【原创】重绘winform的GroupBox
- python并发编程之多进程二
- C#语言中的修饰符
- 【POJ 1740】A New Stone Game
- postgresql,封装数据库语句时,查询报错。
- linux的基本操作(文本编辑工具vim)
- 7、LwIP协议规范翻译——网络接口
- MySQL学习(二) 数据类型
- Activiti工作流搭建---初始化数据库
- vmplayer桥接以及nat配置nginx
- 构建模式--Adapter模式(JAVA)
- Django 性能测试
- ubuntu安装LDAP
- FireFox 书签 缓存 路径设置
热门文章
- poj - 3686 The Windy&#39;s (KM算法)
- 通过继承Thread类来创建多线程 关键词 start
- Java的finally语句在try或catch中的return语句执行之后还是之前?
- SqlSugar最容易使用的ORM
- 【APUE】关于信号的一些常用函数
- Java中正则Matcher类的matches()、lookAt()和find()的差别
- 编写高质量代码:改善C#程序的157个建议
- 【Linux编程】进程终止和exit函数
- 修正iOS从照相机和相册中获取的图片 方向
- 目前使用过的各大厂商rtsp取流的url