错误:包 javax.servlet 不存在

2024-02-21

我试图按照以下指南在我的 Web 应用程序中使用 jsf 2 实现登录过滤器:

https://stackoverflow.com/tags/servlet-filters/info https://stackoverflow.com/tags/servlet-filters/info

在我编译过滤器并在“web-inf/classes”中添加.class(如指南所述)后,过滤器工作了,但我输入了错误的网址重定向到登录页面,所以我从文件夹中删除了filter.class (web-inf/classes) 并尝试再次编译该项目,但失败了,从那时起我得到“包 javax.servlet 不存在”

这很奇怪,因为在它工作之前,我的 pom.xml 中有 javax.servlet ..我尝试清理该项目,但什么也没有。

这是我的过滤器类:

package Bean;

import java.io.IOException;

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.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: rodrigo
 * Date: 28-04-13
 * Time: 06:54 AM
 * To change this template use File | Settings | File Templates.
 */
@WebFilter("/Contenido/*")
public class filtro implements Filter {

    @Override
    public void init(FilterConfig config) throws ServletException {
        // If you have any <init-param> in web.xml, then you could get them
        // here by config.getInitParameter("name") and assign it as field.
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        LoginBean user = (LoginBean) req.getSession().getAttribute("user");

        if (user != null && user.isLoggedIn()) {
            // User is logged in, so just continue request.
            chain.doFilter(request, response);
        } else {
            // User is not logged in, so redirect to index.
            HttpServletResponse res = (HttpServletResponse) response;
            res.sendRedirect(req.getContextPath() + "/Contenido/Login.xhtml");
        }
    }

    @Override
    public void destroy() {
        // If you have assigned any expensive resources as field of
        // this Filter class, then you could clean/close them here.
    }
}

这是错误:

\Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[5,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[6,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[7,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[8,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[9,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[10,20] error: package javax.servlet does not exist
[ERROR] \Users\rodrigo\IdeaProjects\Frutemu\src\main\java\Bean\filtro.java:[11,31] error: package javax.servlet.annotation does not exist

我的 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>Frutemu</groupId>
    <artifactId>Frutemu</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Frutemu Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>Prime Repo</name>
            <url>http://repository.primefaces.org</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>ejb-api</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>3.5</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>all-themes</artifactId>
            <version>1.0.9</version>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.0.2-b10</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- MySQL database driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2.1-b04</version>
            <scope>provided</scope>
        </dependency>
        <!-- OpenJPA framework -->
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-all</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>4.1.2</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>Frutemu</finalName>
        <plugins>
            <!-- Open Jpa -->
            <plugin>
                <groupId>org.apache.openjpa</groupId>
                <artifactId>openjpa-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <includes>**/model/*.class</includes>
                    <addDefaultConstructor>true</addDefaultConstructor>
                    <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                </configuration>
                <executions>
                    <execution>
                        <id>enhancer</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Plugin para levantar una instancia de Tomcat 7 liviana, única para este proyecto -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <url>http://127.0.0.1:8080/manager/text</url>
                    <server>TomcatServer</server>
                    <path>/Frutemu</path>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jasperreports-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile-reports</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <!--note this must be repeated here to pick up correct xml validation -->
                    <dependency>
                        <groupId>net.sf.jasperreports</groupId>
                        <artifactId>jasperreports</artifactId>
                        <version>4.1.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

pom.xml 中缺少 javax.servlet 依赖项。将以下内容添加到依赖项节点:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误:包 javax.servlet 不存在 的相关文章

随机推荐

  • 使用 Daper.Net 和 NPGSQL 将数据插入 PostgreSQL jsonb 列

    我正在尝试使用 Dapper Net 将 JSON 数据插入到 JSONB PostgreSQL 列中 The JSONB 的 NPGSQL 文档 http www npgsql org doc faq html给出了具体的使用说明Npgs
  • 尝试将隐藏的输入值发送到下一页

    我正在尝试根据客户的需求调整 Wordpress Jigoshop 但遇到了一些困难 我需要的是 当选择产品变体时 一些附加选项以单选按钮的形式出现 客户必须选择 我已经设法让一切正常工作 但我现在需要的是在单击提交按钮时将选定的单选按钮发
  • 是否可以对最小化的应用程序进行屏幕截图

    我知道可以捕获另一个应用程序后面的应用程序的屏幕 但我似乎找不到任何有关捕获最小化应用程序屏幕的信息 有人知道这是否可能吗 我不想很快就涉及最大化和最小化应用程序之类的事情 正如 ziplin 所说 对于较新版本的 Windows 这可能是
  • iPhone/iOS 中 viewDidAppear 和 viewDidLoad 之间的区别? [复制]

    这个问题在这里已经有答案了 最重要的是 我一直在开发一个应用程序 似乎如果我放置一个UIAlert in viewDidLoad 它被调用两次 从委托方法UIImagePickerController 如果我把它放进去viewDidAppe
  • python 中的导入是否被视为动态链接?

    用 posix 和通用技术软件开发的话说 是否有import一个纯粹的python 不是cython或c编译的库 模块构成动态链接 不 加载纯 Python 模块不被视为动态链接的一种形式 传统的动态链接将机器代码加载到新的内存块中 并且可
  • 如何将更改的文件添加到 Git 中较旧的(不是最后一次)提交

    在过去的一个小时里 我改变了几件事 并一步步提交它们 但我刚刚意识到我忘记在一些提交之前添加更改的文件 日志看起来像这样 GIT TidyUpRequests u 1 d 0 gt git log commit fc6734b6351f6c
  • 抽象类型集合的获取策略

    所以情况是这样的 假设我有一个用于表示灵活搜索的类结构 public class SearchDefinition public virtual string Name get set public virtual IEnumerable
  • 活动目录属性

    在 stackoverflow 上两个人的帮助下 我已经弄清楚如何使用下面的代码设置 用户无法更改密码 我现在正在想办法如何删除该财产 我认为将拒绝标志设置为 允许 会起作用 但它似乎没有任何作用 如果可能的话 我希望代码使用 Direct
  • iOS:使用 playInputClick 与使用音频工具箱的 (1104) 声音文件之间是否存在性能差异?

    苹果建议使用playInputClick在自定义键盘中模拟点击声 更容易实施AudioServicesPlaySystemSound 1104 所以我的问题就变成了playInputClick提供更好的性能还是同一件事 苹果推荐这样做的原因
  • Plone 4.1.4 安装失败:lxml 构建失败:libxml2:

    预期结果 Successful installtion of Plone 4 1 4 实际结果 Installation fails with libxml2 cmmi failed Stack Ubuntu Ubuntu 10 04 4
  • 上面的注释栏:

    ggplot 中躲避的条形图再次让我难住了 几周前 我询问了有关在此处的栏上方注释文本的问题 LINK https stackoverflow com questions 9815226 annotate values above bars
  • .NET Core MVC 自动迁移后,类库在 VS2017 中丢失智能感知

    将具有两个项目 Web 应用程序和类库 的 VS2015 MVC Core 应用程序迁移到 VS2017 后 我失去了类库中所有视图的智能感知 几乎每个视图中的所有内容都被破坏了 所以我确信迁移工具没有为我处理这是相当基本的事情 即便是 m
  • 如何检查指针是否指向正确对齐的内存位置?

    Given a void 对于某些存储 如何检查它是否指向正确对齐的存储而没有任何实现定义的行为 当然我们有std align http en cppreference com w cpp memory align 但是有更有效的方法吗 t
  • 如何将 OAuth 2 令牌映射到资源服务器中的 UserDetails 对象?

    我有 2 个独立的 Spring Boot 应用程序 一个用作 OAuth 2 授权服务器 另一个用作资源服务器 我正在使用Spring的RemoteTokenServices在我的资源服务器中检查来自授权服务器的令牌 现在 我尝试在资源服
  • 如何在双y轴ggplot上显示图例

    我正在尝试使用 ggplot 绘制双 y 轴图表 首先我要说的是 我并不是在寻找关于这样做是否是良好做法的优点的讨论 我发现它们在查看基于时间的数据来识别两个离散变量的趋势时特别有用 我认为对此进行进一步讨论更适合交叉验证 Kohske h
  • 部署 DacPac 时如何将多个 SQLCMD 变量与 SqlPackage.exe 一起使用?

    我正在使用 sqlpackage exe 部署 dacpac 并且需要为 dacpac 中的部署后脚本传递 SqlCMD 变量 我发现了一个相关问题here https stackoverflow com questions 1550265
  • JAR 插件实现

    让我们有一个 Groovy Java 应用程序 它应该使用一组在外部定义的类 jar files 假设它们位于主可执行 jar 附近 所以 主类 让我们称之为Main 应该加载plugin jar在运行时创建文件并调用该 jar 中定义的类
  • PyDev 在 Eclipse 中导入

    我刚刚在 Ubuntu 10 04 LTS 中安装了 Eclipse Indigo 并使用它安装了 Pydev 我做了以下事情 1 通过在 Window gt Preferences gt PyDev gt Editor gt Interp
  • 致命错误:使用 mongodb php 驱动程序 1.1.2 和 PHP 7.0.2 时未找到“MongoDate”类 - Laravel 5.1

    我正在尝试将 MongoDB 配置为与虚拟 Ubuntu 14 04 计算机上的 Laravel 5 1 Homestead 实例配合使用 我能够使用以下命令成功安装支持 PHP 7 0 的最新版本 MongoDBsudo pecl ins
  • 错误:包 javax.servlet 不存在

    我试图按照以下指南在我的 Web 应用程序中使用 jsf 2 实现登录过滤器 https stackoverflow com tags servlet filters info https stackoverflow com tags se