zoukankan      html  css  js  c++  java
  • javaweb开发过程中的地址写法


    凡是要表示web资源的地址,比如浏览器地址栏中,都是 /
    凡是要表示硬盘地址, 都是  

    public class ServletDemo1 extends HttpServlet {
    
        //实际开发过程中的地址写法
        //如果地址是给服务器用的, / 代表当前web应用
       //如果地址是给客户端用的, / 代表整个网站(一个网站可以有多个web应用)
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            //情况有以下几种
            
            //1.转发(服务器)
            request.getRequestDispatcher("/index.jsp").forward(request, response);
            
            //2. 重定向 (客户端)
            response.sendRedirect("/day06/index.jsp");
            
            //3. 获取地址(服务器)
            this.getServletContext().getRealPath("index.jsp");
            
            //4. 获取请求资源(服务器)
            this.getServletContext().getResource("index.jsp");
            
            //JSP上的两种 (客户端)
            /*<a href="/day06/index.jsp">点击</a>
            
            <form action="/day06/index.jsp"></form>*/
            
        }
    }
  • 相关阅读:
    搞一个先试试
    java map排序
    文件上传
    文件下载
    Filter过滤器
    java编写一个简单的验证码
    centos7安装mysql
    linux安装jdk,tomcat服务器
    DBUtil工具类
    mysql
  • 原文地址:https://www.cnblogs.com/tech-bird/p/4139913.html
Copyright © 2011-2022 走看看