• 吴裕雄--天生自然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>

     

  • 相关阅读:
    vi/vim
    Linux相关知识
    Pikachu实验环境搭建
    DVWA-XSS(Reflected)(反射型跨站脚本攻击)
    DVWA-SQL Injection(Blind)(SQL盲注)
    DVWA—File Upload(文件上传)
    DVWA—Command Injection(命令注入)
    DVWA—Command Injection(命令注入)中出现乱码
    DVWA—Brute Force(暴力破解)
    sqli-labs闯关之61-65关
  • 原文地址:https://www.cnblogs.com/tszr/p/12682522.html
Copyright © 2020-2023  润新知