search

Home  >  Q&A  >  body text

java - Cannot resolve symbol ‘HttpServletRequest'

This project was taken from the online exam https://github.com/Eliteteams/q...

But when IDEA is compiled, an error occurs: Cannot resolve symbol 'HttpServletRequest''HttpServletResponse' 'Cookie'
I have these three jars. The strange thing is that when my project runs, the correct page pops up. What is wrong with this? Already?

仅有的幸福仅有的幸福2724 days ago1766

reply all(4)I'll reply

  • 代言

    代言2017-06-12 09:21:29

    Add this sentence to pom.xml

    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    

    Setting scope to provided means that the running environment has been provided and is only used for compilation and will not be packaged.
    It is not recommended to put the servlet on the classpath, after all, different projects may require different versions.


    Additional sentence: Please select the servlet-api version according to the project's web.xml, or select a new servlet-api version to modify the header of web.xml

    reply
    0
  • 世界只因有你

    世界只因有你2017-06-12 09:21:29

    This is a maven project, there is no need to manually import packages. Right click on the project MAVEN->Update Project

    reply
    0
  • 阿神

    阿神2017-06-12 09:21:29

    The compilation environment does not have javax.servlet-api.jar

    The operating environment has this

    Add javax.servlet-api.jar

    reply
    0
  • 某草草

    某草草2017-06-12 09:21:29

    Add a reference to tomcat, this is the easiest way

    reply
    0
  • Cancelreply