代码
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
@WebServlet("/PractiseServlet03")
public class PractiseServlet03 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
request.getMethod();
request.getRequestURL();
request.getRequestURI();
request.setAttribute("小明", "男");
String name = request.getParameter("name");
Enumeration<String> parameterNames = request.getParameterNames();
String[] names = request.getParameterValues("name");
Map<String, String[]> parameterMap = request.getParameterMap();
request.getRequestDispatcher("ServletDemo01");
response.sendRedirect("www.baidu.com");
ServletContext servletContext = request.getServletContext();
servletContext.setAttribute("李明", "男");
servletContext.getServerInfo();
servletContext.getRealPath("/");
servletContext.getContextPath();
request.getRemoteUser();
request.getRemoteAddr();
request.getRemoteHost();
request.getRemotePort();
}
}