zoukankan      html  css  js  c++  java
  • jsp页面的使用

    public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    

              //1.获取资源文件          
              InputStream is=this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");

    
            String value="aaaa";
            this.getServletContext().setAttribute("data", value);
            request.setAttribute("value", value);
            this.getServletContext().getRequestDispatcher("/1.jsp").forward(request, response);
        }

    1.jsp

    <body>
    <%
    String value = (String) request.getAttribute("value");
    String data = (String) application.getAttribute("data");
    out.write("data:" + data);

    
    

    out.write("value:" + value);
    %>
    This is my JSP page.
    <br>
    </body>
    </html>

     

    获取配置文件

    InputStream is = this.getServletContext().getResourceAsStream( "/WEB-INF/classes/db.properties");

    Properties prop = new Properties(); prop.load(is);

    String url = prop.getProperty("dburl");

    String username = prop.getProperty("username");

    String password = prop.getProperty("password");

    System.out.println(url + " " + username + " " + password);

    //获取硬盘上的实际路径

    String db = this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");

  • 相关阅读:
    instance
    iptables
    centos系统准备
    Leecode no.236 二叉树的最近公共祖先
    Leecode no.235 二叉搜索树的最近公共祖先
    leecode no.98 验证二叉搜索树
    leecode no.109 有序链表转换二叉搜索树
    leecode no.113 路径总和 II
    Leecode no.112 路径总和
    Leecode no.111 二叉树的最小深度
  • 原文地址:https://www.cnblogs.com/zhuawang/p/3395410.html
Copyright © 2011-2022 走看看