(Java)intellij报错 Cannot resolve symbol 'request'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(Java)intellij报错 Cannot resolve symbol 'request'相关的知识,希望对你有一定的参考价值。

我想用request.setAttrinute方法,结果标红报错,网上检查有没有导入servlet.api的方法也试过了还是没用,求大佬指点下怎么破

缺少servlet相关的依赖jar包。
Servlet在java中被抽象为一个接口,它位于javax包中,需要引入servlet-api的jar包方可正常使用,目前最新版本为4.0。
参考技术A 你是用maven管理项目依赖的吗,在maven里面加入对应的依赖 参考技术B 大哥,你好歹贴个图看看啊
直觉上来说,你可能是缺少javax.servlet-api的包

Intellij IDEA 报错java.lang.NoClassDefFoundError

Intellij IDEA 报错java.lang.NoClassDefFoundError

11-Aug-2018 23:48:24.686 严重 [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [com.wbg.testservlet] in context with path [] threw exception [Servlet execution threw an exception] with root cause

 java.lang.ClassNotFoundException: com.wbg.testDao

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)

at com.wbg.testService.select(testService.java:9)

at com.wbg.testservlet.doGet(testservlet.java:19)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)

 

原因没有导入完整的jar包

 

解决方案:

方案一:

其实是因为jar包未被部署,那么在进行页面请求的时候,就会找不到jar包,那么就会报错….. 
解决方案如下: 
Projecture—>Artifacts–>选择打包部署项目—->Output Layout–>Web-INF—->查看下面是否有lib目录(如果没有lib目录,可自行创建)—>右边的jar包添加到lib目录下 
以上,即可解决ClassNotFound的异常 

方案二:

右键->F4进入,看到有报错,然后一直Add到没有就可以了,看图

 

 

 

 

成功解决

 

以上是关于(Java)intellij报错 Cannot resolve symbol 'request'的主要内容,如果未能解决你的问题,请参考以下文章

IntelliJ cannot log in to GitHub上传github报错解决

IntelliJ IDEA总是提示Cannot resolve symbol

Android 新建项目报错(CANNOT RESOLVE SYMBOL R)

Androidproject中增加图片,报错cannot be resolved or is not a field

Java 开发工具IntelliJ IDEA 12.0 总是提示Cannot resolve symbol

R文件报错:cannot resolve symbol ‘R’