1.获得Servlet初始化参数
web.xml配置
<context-param>
<param-name>hp</param-name>
<param-value>http://www.baidu.com</param-value>
</context-param>
MyServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//HttpServletRequest request 请求
//HttpServletResponse response 响应类
String value =this .getServletContext().getInitParameter("hp");
System.out.println(value);
}
2.页面重定向
请求重定向,可以跳转到其他网站
response.sendRedirect("url");
response.sendRedirect("http:www,baidu.com");
请求转发,当前域,不包含
request.getRequestDispatcher("url").forward(request,response);
request.getRequestDispatcher("new_page.html").forward(request,response);
请求包含,当前域,包含
request.getRequestDispatcher("url").include(request.response);
request.getRequestDispatcher("new_page.html").include(request,response);