类中代码
package com.yin; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class RedirectServlet extends HttpServlet { public RedirectServlet() { super(); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.sendRedirect("/response1_war/img"); } @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doGet(req, resp); } }
web.xml中代码
<servlet> <servlet-name>red</servlet-name> <servlet-class>com.yin.RedirectServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>red</servlet-name> <url-pattern>/re</url-pattern> </servlet-mapping>
标签:重定向,resp,req,HttpServletResponse,Response,import,servlet,javax From: https://www.cnblogs.com/insoon/p/17051782.html