zoukankan      html  css  js  c++  java
  • 通过location响应头实现重定向

    package day08;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    /**
     * 案例【location+302】 请求重定向
     * @author mzy
     *
     */
    public class ResponseDemo02 extends HttpServlet {
    
    	private static final long serialVersionUID = 1288883616651269766L;
    
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		response.setContentType("text/html;charset=utf-8");	
    		request.setCharacterEncoding("utf-8");
    		// 设置302状态码
    		response.setStatus(302);
    		// 设置location响应头
    		response.setHeader("location", "../adv.html");
    		// 注意:一次重定向,向服务器发送两次请求
    		
    	}
    	
    	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		response.setContentType("text/html;charset=utf-8");
    		request.setCharacterEncoding("utf-8");
    		
    		
    		
    	}
    
    }
    

  • 相关阅读:
    八皇后问题
    Catalan数与出栈顺序个数,Java编程模拟
    推荐系统中的协同过滤
    集成学习
    背包问题
    逆波兰表达式
    [leetcode]775. Global and Local Inversions
    [LeetCode]Minimum Moves to Equal Array Elements1,2
    链接属性
    常用表格属性
  • 原文地址:https://www.cnblogs.com/mzywucai/p/11053529.html
Copyright © 2011-2022 走看看