码迷,mamicode.com
首页 > 其他好文 > 详细

servlet 相应头重定向

时间:2017-05-12 01:53:19      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:imp   demo   请求   cat   void   大小写   status   writer   oca   

package demoservllet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Servlet01 extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  response.setStatus(302);  //设置请求状态  302重定向
  response.setHeader("Location", "/WEB14/servlet02");//设置请求头 Location固定的L大小写都可以  url=("/WEB14/servlet02")
  }

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  doGet(request, response);
  }
}

 

package demoservllet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Servlet02 extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.getWriter().write("hello haohao...");//页眉打印的东西
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
  }
}

 

servlet 相应头重定向

标签:imp   demo   请求   cat   void   大小写   status   writer   oca   

原文地址:http://www.cnblogs.com/yjhlsbnf/p/6843568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!