${pageContext.request.contextPath} //jsp中

request.getContextPath() //Servlet中

两者获取到的都是"/项目名称"

这里再加一种视频中推荐的写法:

  在jsp页面中引入jstl标签库:<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

  然后在需要写地址的地方 :<c:url value='/LoginServlet' />

  其中,value中的值会自动加/项目名,注意引号问题即可,好处是直观

相关文章:

  • 2021-09-19
  • 2022-12-23
  • 2022-02-07
  • 2021-08-08
  • 2022-12-23
  • 2021-05-28
  • 2021-11-16
  • 2021-04-06
猜你喜欢
  • 2021-04-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2022-01-04
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案