servlet 相应头重定向
Posted yjhsbn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了servlet 相应头重定向相关的知识,希望对你有一定的参考价值。
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 相应头重定向的主要内容,如果未能解决你的问题,请参考以下文章