IntelliJ IDEA无法解析导入javax.servlet。*; [英] IntelliJ IDEA cannot resolve import javax.servlet.*;

查看:299
本文介绍了IntelliJ IDEA无法解析导入javax.servlet。*;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我让我的项目完美运行,我决定安装一个新硬盘(SSD),现在我无法正常运行。

So I had my project working perfectly and I decided to install a new hard drive (SSD) and now I cannot get it to run correctly.

我正在使用Intellij和我所有这些导入都有问题。

I am using Intellij and am having all of these imports have issues.

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

他们说无法解析符号。

同样在我的web.xml中,我有这个。

Also in my web.xml I have this.

<filter>
    <filter-name>LoginFilter</filter-name>
    <filter-class>com.mkyong.LoginFilter</filter-class>
</filter>

it state

com.mkyong.LoginFilter is not assignable to javax.servlet.Filter

我要去包括我的web.xml以防万一有人需要它。

Im going to include my web.xml just in case someone needs it.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
id="WebApp_ID" version="2.5">

<display-name>JavaServerFaces</display-name>

<resource-ref>
<description>MySQL Datasource example</description>
<res-ref-name>jdbc/mkyongdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/default.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

  <!-- Map these files with JSF -->
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>

 <servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.faces</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>LoginFilter</filter-name>
    <filter-class>com.mkyong.LoginFilter</filter-class>
</filter>
<!-- Set the login filter to secure all the pages in the /secured/* path of the application  -->
<filter-mapping>
    <filter-name>LoginFilter</filter-name>
    <url-pattern>/secured/*</url-pattern>
</filter-mapping>

<!-- By default go to secured welcome page -->
<welcome-file-list>
    <welcome-file>secured/welcome.xhtml</welcome-file>
</welcome-file-list>

</web-app>

这是我现在得到的错误。

This is the error I am getting now.

   javax.servlet.ServletException: Servlet.init() for servlet Faces Servlet threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)
root cause

java.lang.IllegalStateException: Application was not properly initialized at startup, could not    find Factory: javax.faces.context.FacesContextFactory
javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:800)
javax.faces.FactoryFinder.getFactory(FactoryFinder.java:302)
javax.faces.webapp.FacesServlet.init(FacesServlet.java:186)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)

我最初也在使用apache tomcat 8然后我认为这可能是问题而且我改变了它到7然后到6.如果你还需要其他任何东西请告诉我!

I was also using apache tomcat 8 at first then I thought that might be the issue and I changed it to 7 then to 6. If you need anything else please let me know!

这里是请求的POM.xml。

here is the POM.xml as requested.

  <project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
 http://maven.apache.org/maven-v4_0_0.xsd">

 <modelVersion>4.0.0</modelVersion>
 <groupId>com.mkyong.common</groupId>
 <artifactId>JavaServerFaces</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>JavaServerFaces Maven Webapp</name>
 <url>http://maven.apache.org</url>

<repositories>
 <repository>
   <id>java.net.m2</id>
   <name>java.net m2 repo</name>
   <url>http://download.java.net/maven/2</url>
 </repository>
</repositories>

<dependencies>

  <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-web</artifactId>
      <version>3.2.5.RELEASE</version>
  </dependency>

<!-- MySQL database driver -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.9</version>
</dependency>

<!-- Spring framework --> 
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>2.5.6</version>
</dependency>


<!-- For Servlet Container like Tomcat -->
<!-- http://download.java.net/maven/2 -->
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>2.1.0-b03</version>
</dependency>



<!-- EL 2.2 to support method parameter in EL -->
<dependency>
  <groupId>org.glassfish.web</groupId>
  <artifactId>el-impl</artifactId>
  <version>2.2</version>
</dependency>


<!-- http://repo1.maven.org/maven2/ -->
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

  <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
  </dependency>

  <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
  </dependency>


</dependencies>


 <build>
   <finalName>JavaServerFaces</finalName>

  <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>2.3.1</version>
       <configuration>
           <source>1.6</source>
           <target>1.6</target>
       </configuration>
   </plugin>
</plugins>


推荐答案

servlet-api.jar是服务器的一部分(在本例中为Tomcat)。您需要在POM中声明对该jar的引用并在提供的范围内标记它(如果由于某种原因您没有使用maven),则需要将其添加到类路径中(您的Web模块中的库)项目)。

The servlet-api.jar is part of your server (Tomcat in this case). You need to either state a reference to that jar in your POM and mark it in 'provided' scope or (if you are not using maven for some reason) you need to add it to your classpath (the libraries of your web module in your project).

重新安装HD后,你的Tomcat安装程序或maven repo可能会有所不同。这似乎是一个环境问题。

The chances are perhaps that your Tomcat installation forder or maven repo is different after your HD reinstall. It seems to be like an environmental issue.

这篇关于IntelliJ IDEA无法解析导入javax.servlet。*;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆