配置jsp
<servlet>
<servlet-name>hellojsp</servlet-name>
<jsp-file>/hello.jsp</jsp-file>
<init-param>
<param-name>test</param-name>
<param-value>testValue</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>hellojsp</servlet-name>
<url-pattern>/hellojsp</url-pattern>
</servlet-mapping>
转发和重定向
//请求的转发
//1.调用HttpServletRequest 的getRequestDispatcher()方法获取RequestDispatcher对象
//调用getRequestDispatcher需要传入转发的地址
String path = "testServlet";
RequestDispatcher requestDispatcher = request.getRequestDispatcher("/" + path);
//2.调用HttpServletRequest的forward(request,response) 进行请求的转发
requestDispatcher.forward(request, response);
//执行请求的重定向,直接调用Response.sendRedirect(path)方法
String path = "testServlet";
response.sendRedirect(path);
中文乱码
JSP小结