页面导航
-请求重定向 - 不共享request里的内容
response.sendRedirect("url")
-请求转发 - 共享request里的内容
request.getRequestDispatcher("url").forward(request, response)
-请求包含
request.getRequestDispatcher("url").include(request, response)
package com.zhaofei.servlet;
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 servletforme extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
// 页面重定向
resp.sendRedirect("http://wenku.baidu.com/");
// 这个事请求包含
req.getRequestDispatcher("/Success.html").forward(req, resp);
// 重点是此处的页面跳转 请求转发
req.getRequestDispatcher("/Success.html").forward(req, resp);
System.out.println(this.getInitParameter("username"));
System.out.println(this.getServletContext().getInitParameter("url"));
System.out.println("doGet()");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("doPost()");
}
}