标签: http-status-code-404

在JavaScript中检测404

在我的JavaScript中,我正在尝试重定向到第三方页面.它可以在新窗口中打开页面,也可以在框架内打开页面,具体取决于用户设置.像这样的东西:

if (newWindow)
{
   window.open(url, targer);
}
else
{
   theFrame = url;
}
Run Code Online (Sandbox Code Playgroud)

我想要做的是显示我的自定义页面,以防第三方网站关闭或页面不可用.基本上是在404错误的情况下.

解决这个问题的最佳方法是什么?

javascript asp.net http-status-code-404

0
推荐指数
1
解决办法
422
查看次数

如何禁用特定 Wordpress url 上的 404 标头

我使用此代码将特定 url 重定向到我定制的 Wordpress 主题上的 php 文件:

add_action('wp', function() {
if ( trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/') === 'pagename' ) {
include(locate_template('mysciprt.php'));
exit();
}});
Run Code Online (Sandbox Code Playgroud)

(我知道我可以使用重写规则,但出于一些原因我需要使用此代码)。

它的工作很棒。问题是该页面仍然有一个 404 状态的 http 标头。这是一个问题,原因有几个(其中一些是:seo,不能使用发布脚本......)。

我的问题是:有什么办法可以解决吗?

我尝试过的:

我尝试添加:

global $wp_query;
status_header(200);
$wp_query->is_page = true;
$wp_query->is_404  = false;
Run Code Online (Sandbox Code Playgroud)

一开始没有帮助,然后我改变了我action('wp'..action('init'...,它起作用了!但问题是我使用'wp'而不是'init'因为我需要get_query_var()在这个脚本上使用而我不能在使用'init'动作时使用。

php wordpress url-rewriting http-headers http-status-code-404

0
推荐指数
1
解决办法
1648
查看次数

在 tomcat 上部署 Spring Boot 应用程序时出现 404 错误

从 Eclipse 或 Intellij idea 运行 Spring Boot 应用程序时,它会在嵌入式 tomcat 服务器上运行。但是当部署在外部 tomcat 服务器上时,它会出现 404 错误。

java spring tomcat http-status-code-404

0
推荐指数
1
解决办法
5692
查看次数

Spring boot在多模块项目中找不到jsp

我正在使用 spring boot,我决定只是为了将我的项目分成模块。我有 4 个模块,Web、服务、存储库、域。除了JSP,一切正常,spring 找不到这些页面。但是当我没有将我的项目拆分为模块时,它就起作用了。我没有改变配置。

这是我的网络模块结构

在此处输入图片说明

Runner 位于 web 模块中,这里是:

@SpringBootApplication(scanBasePackages = "kz.epam.javalab.daimoncool")
public class WebApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的 application.properties:

spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.physical_naming_strategy=com.vladmihalcea.hibernate.type.util.CamelCaseToSnakeCaseNamingStrategy

spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
Run Code Online (Sandbox Code Playgroud)

父 POM xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>kz.epam.javalab.daimoncool</groupId>
    <artifactId>newsmanagementparent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>newsmanagementparent</name>
    <packaging>pom</packaging>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent …
Run Code Online (Sandbox Code Playgroud)

java spring jsp http-status-code-404 spring-boot

0
推荐指数
1
解决办法
967
查看次数

刷新相同的 URL 会在 angular 中找不到 404

我在服务器上托管了我的 angular 应用程序。当我单击服务器 url 时,它会将我重定向到登录页面。但是,当我刷新以 login 为后缀的相同 url 时,它给了我 404 not found 错误。给出的原始网址没有登录后缀。请帮忙。

在此处输入图片说明

在此处输入图片说明

在 app.routing.module.ts 中,我配置了这样的路由器路径:

在此处输入图片说明

http-status-code-404 angular angular8

0
推荐指数
1
解决办法
2882
查看次数

使用 MethodValidationPostProcessor 时 Spring 返回 404

我的测试 Spring Boot 应用程序有问题。它工作得很好,但是当我通过添加依赖项等并添加以下内容来启用 Spring 验证时@Configuration

@Configuration
public class TestConfiguration {

  @Bean
  public MethodValidationPostProcessor methodValidationPostProcessor() {
    return new MethodValidationPostProcessor();
  }
}
Run Code Online (Sandbox Code Playgroud)

我的测试端点得到 404。

{
    "timestamp": 1601507037178,
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/test"
}
Run Code Online (Sandbox Code Playgroud)

我已经应用了类似问题的一些解决方案/建议(例如此处此处),但没有成功。

这是我的代码: https: //github.com/zolv/error-handling-test

API接口:

@Validated
public interface TestApi {

  @PostMapping(
      value = "/test",
      produces = {"application/json"},
      consumes = {"application/json"})
  @ResponseBody
  ResponseEntity<TestEntity> getTest(@Valid @RequestBody(required = false) TestEntity request);
}
Run Code Online (Sandbox Code Playgroud)

TestEntity只是为了发送一些东西:

@Data
public class TestEntity { …
Run Code Online (Sandbox Code Playgroud)

java validation http-status-code-404 spring-boot

0
推荐指数
1
解决办法
1112
查看次数

无法使用 try 和 catch 处理 axios 中的 404 错误

我一直在尝试构建一个天气应用程序,但在验证 http 状态时遇到一些麻烦,以防用户自愿插入不存在的城市名称或用户在输入字段中输入错误。

唯一的问题是我找不到在 axios Promise 中插入 status !== 200 的方法。

200 状态工作得很好,但 404 状态却不行。我确信承诺中的某个地方有错误,但我无法找到解决方法。

此外,当我控制台记录错误时,它会显示以下消息:

console.log 中出现错误

Uncaught (in promise) Error: Request failed with status code 404
    at e.exports (createError.js:16)
    at e.exports (settle.js:17)
    at XMLHttpRequest.E (xhr.js:66)
Run Code Online (Sandbox Code Playgroud)

JavaScript

try{            
            axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${api_key}`).then(
                
            async response => {
                
            let data = await response.data

            if (response.status !== 200) {
            
                throw new Error(response.status);
            
                } else {
            
            console.log(data)
            document.getElementById('hum').textContent = data.main.humidity;
            document.getElementById('feels-like').textContent = data.main.feels_like;
                }}
        )
        
        } catch(error) {
            if (response.status === 404) {
                console.log(`Err: ${error}`);
                throw …
Run Code Online (Sandbox Code Playgroud)

api promise http-status-code-404 axios

0
推荐指数
1
解决办法
6459
查看次数

Golang 使用响应中的正文更改 HTTP 响应状态代码 201

在响应正文中包含 JSON 对象时,如何将响应状态代码设置为 201?我似乎无法同时执行这两项操作——要么返回带有消息正文的 200,要么返回没有消息正文的 201。

http httpresponse go http-status-code-404

-1
推荐指数
1
解决办法
6234
查看次数

400 和 404 HTTP 错误的区别

400 和 404 HTTP 错误有什么区别?
你能告诉我一个例子来理解差异吗?

谢谢你。

http http-status-code-404 http-status-code-400

-1
推荐指数
1
解决办法
5513
查看次数

到处都是404页面 - 迁移后无法访问后端

我们的网站最近被转移.

我们按照本教程中的说明操作:http://www.magentocommerce.com/wiki/groups/227/move_magento_to_another_directory

我认为一切都工作得很好......现在我得到了404全面的......没有任何东西出现,我无法访问后端.

谁能给我任何指针?

migration magento http-status-code-404

-2
推荐指数
1
解决办法
903
查看次数