zoukankan      html  css  js  c++  java
  • 【Struts APP_PATH】StartSystemListener

    StartSystemListener
    package k.filter;
    
    import javax.servlet.ServletContext;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    
    public class StartSystemListener implements ServletContextListener {
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            //1.将项目上下文路径(request.getContextPath())放置到application域中.
            ServletContext application = sce.getServletContext();
            application.setAttribute("APP_PATH", application.getContextPath());
            System.err.println("=============Servlet容器创建成功 APP_PATH 被放到ServletContext作用域============= " + application.getContextPath());
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
    
        }
    }

    web.xml

        <listener>
            <display-name>StartSystemListener</display-name>
            <listener-class>k.filter.StartSystemListener</listener-class>
        </listener>

    login.jsp

    <h1>登录页面</h1>
    <form action="${APP_PATH}/login.do" method="post">
        账号:<input type="text" name="userName" value="11哈哈"> <br>
        密码: <input type="password" name="password" value="1"> <br>
        <input type="submit" value="submit"> <br>
    </form>
  • 相关阅读:
    Python程序执行时的不同电脑路径不同问题
    Python写的计算器程序(主要目的在于熟悉下正则表达式)
    占位符
    selenium自动化测试浏览器驱动安装(属于转载文章)
    python的pip升级问题
    索引
    视图
    事务
    引擎
    约束
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12301999.html
Copyright © 2011-2022 走看看