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");
        }
    
    
    
  • 相关阅读:
    python中类中的@property
    Python列表的三种遍历(序号和值)的方法
    Numpy一文全了解
    python中list操作方法
    Material Design
    android动画xml
    java配置opencv-在eclipse中
    android 重装sdk或者系统的时模拟器出现can open ****
    hdu acm 1005
    hdu acm 1007
  • 原文地址:https://www.cnblogs.com/0x10-lexsblog/p/14220051.html
Copyright © 2011-2022 走看看