zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Clean Code(三):注释
    Clean Code(二):函数
    mysql中查询某字段所在的表方法
    对于POI的XSSFCell 类型问题
    Clean Code 笔记 (一):命名
    java 注解
    搭建Eureka服务时报Cannot execute request on any known server 错误
    Jquery获取子父类方法
    Oracle 查询id相同多个数据取一条
    Ajax的使用及后台如何传参
  • 原文地址:https://www.cnblogs.com/kaiwen/p/6577086.html
Copyright © 2011-2022 走看看