StrutsAPP_PATHStartSystemListener

【StrutsAPP_PATHStartSystemListener】业无高卑志当坚,男儿有求安得闲?这篇文章主要讲述StrutsAPP_PATHStartSystemListener相关的知识,希望能为你提供帮助。

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="https://www.songbingjia.com/android/11哈哈"> < br> 密码: < input type="password" name="password" value="https://www.songbingjia.com/android/1"> < br> < input type="submit" value="https://www.songbingjia.com/android/submit"> < br> < /form>

 

    推荐阅读