首页 > 其他分享 >Response重定向

Response重定向

时间:2023-01-14 14:22:21浏览次数:37  
标签:重定向 resp req HttpServletResponse Response import servlet javax

类中代码

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

相关文章