gpt4 book ai didi

java - 无法从 HTML 页面调用 Java Filter

转载 作者:行者123 更新时间:2023-12-02 04:44:35 25 4
gpt4 key购买 nike

我正在尝试了解过滤器。我使用netbens 8.02。

我有一个简单的 html 页面:

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/css.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<nav>
<form action="f">
<label for="username">User: </label><input name ="username" type="text">
<label for="password">Password: </label><input name ="password" type="password">
<input type="submit" value="Vai">
</form>
</nav>

<section id ="page">

</section>
</body>
</html>

我正在尝试调用一个名为“f”的过滤器,但每次我构建并运行 broject 并在尝试登录后尝试加载过滤器时,都会收到 404 消息:

type Status report

message /Filtri/f

description The requested resource is not available.

这是我的 web.xml 文件:(由 netbeans 构建)

> <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1"
> xmlns="http://xmlns.jcp.org/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
> http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
> <filter>
> <filter-name>f</filter-name>
> <filter-class>f</filter-class>
> </filter>
> <filter-mapping>
> <filter-name>f</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
> <session-config>
> <session-timeout>
> 30
> </session-timeout>
> </session-config> </web-app>

这是我的项目层次结构:Project hierachy

你能帮我吗?

最佳答案

Filter 拦截或者预处理一个请求,但是请求仍然需要到一个资源(一个servlet,一个jsp) > 或 html 页面),否则服务器将响应 404

您正在请求 f 处的资源,但尽管过滤器可能会拦截该请求,但一旦过滤器完成处理,服务器仍会尝试将您发送到 f code> 在您的上下文中没有任何内容。

关于java - 无法从 HTML 页面调用 Java Filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29768997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com