首页前端开发HTML[JSP] 实现请求转发

[JSP] 实现请求转发

时间2023-10-21 15:00:03发布访客分类HTML浏览1305
导读:在服务器端对客户端请求时行转发对其它的对象,如果jsp网页或Servlet用三个 jsp网页来演示转发:forword1.jsp, 用来提交表单, 将表单内容提交给 forwrod2.jsp, forward1.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>
    

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: [JSP] 实现请求转发
本文地址: https://pptw.com/jishu/504580.html
SAP 电商云 footer 区域 Link Component HTML 源代码的详细讲解 2023最新Vue3全家桶+Express全栈开发通用后台管理系统

游客 回复需填写必要信息