java ServletContext getContextPath()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3120860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:27:20  来源:igfitidea点击:

ServletContext getContextPath()

javaweb-applicationsnetbeansservlets

提问by walnutmon

I checked the javadocs of the Tomcat library I have included under my Netbeans project, and when I deploy the code works fine, but when I do a clean-build of my web project I get a "cannot find symbol" on the getContextPath() method of the ServletContext interface

我检查了我在 Netbeans 项目下包含的 Tomcat 库的 javadocs,当我部署代码时工作正常,但是当我对我的 web 项目进行干净构建时,我在 getContextPath() 上得到一个“找不到符号” ServletContext 接口的方法

It's driving me completely insane because in order to run my tests and so on I have to first deploy, then test, if I clean and build, or clean and run tests I get this error...

这让我完全疯了,因为为了运行我的测试等等,我必须首先部署,然后测试,如果我清理和构建,或者清理并运行测试,我会收到这个错误......

Anyone have any clue what could be causing this issue? Is there a library I have to update or something?

任何人都知道可能导致此问题的原因是什么?是否有我必须更新的图书馆或其他什么?

回答by Jon Skeet

I suspect it's not in the version of ServletContextyou're building against, but it isin the version you're deploying against. According to the docs of version 2.5it was introduced in2.5. So basically change the servlet.jar you're building against to be the 2.5 one, and it should be fine.

我怀疑这是不是在版本ServletContext正在构建对的,但它在版本要部署打击。根据2.5 版文档,它是2.5中引入。因此,基本上将您正在构建的 servlet.jar 更改为 2.5,它应该没问题。