jsp请求转发小例子(转载)
Posted 智云
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jsp请求转发小例子(转载)相关的知识,希望对你有一定的参考价值。
在服务器端对客户端请求时行转发对其它的对象,如果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请求转发小例子(转载)的主要内容,如果未能解决你的问题,请参考以下文章