例をオンラインにしていましたが、特定の関数request.getServletContext()。getServletRegistrations()を使用していました。私はそれがエラーなしで正常に動作しますが、使用してMavenのは、これらの同じメソッドが定義されていない通常の動的Webプロジェクトでこれと同じ機能を使用する場合は、この機能getServletContext()型は、EclipseのmavenプロジェクトのHttpServletRequest型では未定義です
// Check the target of the request is a servlet?
private boolean needJDBC(HttpServletRequest request) {
System.out.println("JDBC Filter");
String servletPath = request.getServletPath();
// => /abc/mnp
String pathInfo = request.getPathInfo();
String urlPattern = servletPath;
if (pathInfo != null) {
// => /spath/*
urlPattern = servletPath + "/*";
}
// Key: servletName.
// Value: ServletRegistration
Map<String, ? extends ServletRegistration> servletRegistrations = request.getServletContext()
.getServletRegistrations();
// Collection of all servlet in your webapp.
Collection<? extends ServletRegistration> values = servletRegistrations.values();
for (ServletRegistration sr : values) {
Collection<String> mappings = sr.getMappings();
if (mappings.contains(urlPattern)) {
return true;
}
}
return false;
}
を認識しません。私は request.getServletContext()を変更しようとしました。getServletRegistrations();
~ request.getSession()。getServletContext()。getServletRegistrations();
getSession.getServletContext()は認識されましたが、getServletRegistrations()は認識されません。私は私のpom.xmlにいくつかの依存関係を追加
<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.ers</groupId>
<artifactId>ERSProject</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ERSProject Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<!-- Repository for ORACLE ojdbc6. -->
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>
<dependencies>
<!-- Oracle database driver -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.web/javax.servlet.jsp.jstl -->
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.5-b03</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/javax.servlet.jsp.jstl-api -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>ERSProject</finalName>
</build>
私はそれが依存関係の問題となってきたかもしれない考え出し任意の助けいただければ幸いです。ありがとうございました。
このjavax.servlet-apiをpom.xmlに追加します。そして、あなたのpom.xmlが、メインプロジェクトフォルダのどこにある正しい場所にあるか確かめてください。 mvn clean installコマンドを入力し、それが正常にインストールされていることを確認してから、.m2フォルダを確認します。そこにはjavax.servlet-api jarが存在します。すべてがうまくいけば、MavenとEclipseの間にパスの競合があることを確認する必要があります。 – erhun
この回答を確認するhttps://stackoverflow.com/questions/29314336/how-to-figure-out-why-certain-javax-servlet-dependency-is-added-to-a-maven-proje –