zoukankan      html  css  js  c++  java
  • Servlet中如何实现页面转发

    在Servlet中实现页面转发主要是利用RequestDispatcher接口实现的。此接口可以把一个请求转发到另一个JSP页面上。
         forward():把请求转发到服务器上的另一个资源。
         include():把服务器上的另一个资源包含到响应中。
    例: 编写一个Servlet程序ForwardServlet,在网站运行时,将页面直接跳转到网站首页index.jsp。

     1 package com.mhb;
     2 
     3 import java.io.IOException;
     4 import java.io.PrintWriter;
     5 
     6 import javax.servlet.RequestDispatcher;
     7 import javax.servlet.ServletException;
     8 import javax.servlet.http.HttpServlet;
     9 import javax.servlet.http.HttpServletRequest;
    10 import javax.servlet.http.HttpServletResponse;
    11 
    12 public class ForwardServlet extends HttpServlet {
    13 
    14 public void init() throws ServletException {
    15 }
    16 
    17 public void doGet(HttpServletRequest request, HttpServletResponse response)
    18 throws ServletException, IOException {
    19 RequestDispatcher requestDispatcher = request.getRequestDispatcher("index.jsp");
    22 requestDispatcher.forward(request, response);
    23 }
    24 
    25 public void doPost(HttpServletRequest request, HttpServletResponse response)
    26 throws ServletException, IOException {
    27 }
    28 
    29 public void destroy() {
    30 super.destroy(); 
    31 }
    32 }
  • 相关阅读:
    vi编辑器
    在shell脚本中使用函数
    在shell脚本中进行条件控制以及使用循环
    shell指令expr和test指令
    利用ps指令查看某个程序的进程状态
    shell变量的使用
    创建和运行shell脚本程序
    关于强制类型转换(c语言)
    elastic 常用查询操作
    elastic 集群安装
  • 原文地址:https://www.cnblogs.com/tdcqma/p/4757235.html
Copyright © 2011-2022 走看看