配置 JavaWeb 项目URL地址前缀 127.0.0.1:8080/项目名

配置 JavaWeb 项目URL地址 ==== 127.0.0.1:8080/项目名

方法一: 在将jsp中 ${pageContext.request.contextPath}

方法二:${cxt}

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class AppListener implements ServletContextListener{

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ServletContext context = sce.getServletContext();
		context.setAttribute("cxt", context.getContextPath());
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		
	}

}

你可能感兴趣的:(jsp)