zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然JAVA开发JSP-Servlet学习笔记:使用config获取JSP参数

    <%-- 
        Document   : configTest2
        Created on : 2020-4-11, 21:49:46
        Author     : Administrator
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>测试config内置对象</title>
        </head>
        <body>
            <!-- 输出该JSP名为name的配置参数 -->
            name配置参数的值:<%=config.getInitParameter("name")%><br/>
            <!-- 输出该JSP名为age的配置参数 -->
            age配置参数的值:<%=config.getInitParameter("age")%>
        </body>
    </html>
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                          http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1"
             metadata-complete="true">
        <!-- 配置第一个参数:driver -->
        <context-param>
            <param-name>driver</param-name>
            <param-value>com.mysql.cj.jdbc.Driver</param-value>
        </context-param>
        <!-- 配置第二个参数:url -->
        <context-param>
            <param-name>url</param-name>
            <param-value>jdbc:mysql://localhost:3306/taobao</param-value>
        </context-param>
        <!-- 配置第三个参数:user -->
        <context-param>
            <param-name>user</param-name>
            <param-value>root</param-value>
        </context-param>
        <!-- 配置第四个参数:pass -->
        <context-param>
            <param-name>pass</param-name>
            <param-value>admin</param-value>
        </context-param>
        
        <servlet>
            <!-- 指定Servlet名字 -->
            <servlet-name>config</servlet-name>
            <!-- 指定将哪个JSP页面配置成Servlet -->
            <jsp-file>/configTest2.jsp</jsp-file>
            <!-- 配置名为name的参数,值为crazyit.org -->
            <init-param>
                <param-name>name</param-name>
                <param-value>crazyit.org</param-value>
            </init-param>
            <!-- 配置名为age的参数,值为30 -->
            <init-param>
                <param-name>age</param-name>
                <param-value>30</param-value>
            </init-param>
        </servlet>
        <servlet-mapping>
            <!-- 指定将config Servlet配置到/config URL-->
            <servlet-name>config</servlet-name>
            <url-pattern>/config</url-pattern>
        </servlet-mapping>
      
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
            <welcome-file>index.htm</welcome-file>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    
    </web-app>

     

  • 相关阅读:
    P2184 贪婪大陆
    codeforces-1348-D Phoenix and Science
    联系我
    留言板
    友链
    java集合ArrayList按指定字段排序
    linux下设置oracle开机自启动
    微信公众号开发参考教程
    java生成快递单并调用打印机打印
    java生成128A条形码
  • 原文地址:https://www.cnblogs.com/tszr/p/12682522.html
Copyright © 2011-2022 走看看