zoukankan      html  css  js  c++  java
  • 实现重定向

    什么是重定向?

    客户端请求一个web资源,这个web资源让客户端访问另一个web资源

    案例:用户登录

    void sendRedirect(String var1) throws IOException;
    
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
        /*
            resp.setHeader("Location","/r/img");
            resp.setStatus(302);
             */
        resp.sendRedirect("/r/img");//重定向
    }
    
    <%--这里提交的路径,需要寻找到项目的路径--%>
    <%--${pageContext.request.contextPath}代表当前的项目--%>
    
    <form action="${pageContext.request.contextPath}/login" method="get">
        用户名:<input type="text" name="username"> <br>
        密码:<input type="password" name="password"> <br>
        <input type="submit">
    </form>
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            //处理请求
            String username = req.getParameter("username");
            String password = req.getParameter("password");
    
            System.out.println(username+":"+password);
    
            //重定向时候一定要注意,路径问题,否则404;
            resp.sendRedirect("/r/success.jsp");
        }
    
    
    
  • 相关阅读:
    053-509
    053-298
    053-255
    css实现省略号
    github上写blog
    解决内容被挤压缩小问题
    request.getRequestDispather().forward()与response.sendRedirect()
    资料,来自HTML5前端开发学习⑤群
    checkbox与jq<转>2
    checkbox与jq<转>
  • 原文地址:https://www.cnblogs.com/0x10-lexsblog/p/14220051.html
Copyright © 2011-2022 走看看