标签: http-status-code-404

如何检查URL是否存在或使用Java返回404?

String urlString = "http://www.nbc.com/Heroes/novels/downloads/Heroes_novel_001.pdf";
URL url = new URL(urlString);
if(/* Url does not return 404 */) {
    System.out.println("exists");
} else {
    System.out.println("does not exists");
}
urlString = "http://www.nbc.com/Heroes/novels/downloads/Heroes_novel_190.pdf";
url = new URL(urlString);
if(/* Url does not return 404 */) {
    System.out.println("exists");
} else {
    System.out.println("does not exists");
}
Run Code Online (Sandbox Code Playgroud)

这应该打印

exists
does not exists
Run Code Online (Sandbox Code Playgroud)

测试

public static String URL = "http://www.nbc.com/Heroes/novels/downloads/";

public static int getResponseCode(String urlString) throws MalformedURLException, IOException {
    URL u = new URL(urlString); 
    HttpURLConnection huc =  (HttpURLConnection)  u.openConnection(); 
    huc.setRequestMethod("GET"); …
Run Code Online (Sandbox Code Playgroud)

java url http-status-code-404

72
推荐指数
5
解决办法
13万
查看次数

urlencoded正斜杠正在破坏URL

关于系统

我的项目中有这种格式的URL: -

http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0
Run Code Online (Sandbox Code Playgroud)

其中关键字/类对意味着使用"class"关键字进行搜索.

我有一个常见的index.php文件,它为项目中的每个模块执行.只有一个重写规则可以从URL中删除index.php: -

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
Run Code Online (Sandbox Code Playgroud)

我在阅读搜索URL时准备搜索URL和urldecode()时使用urlencode().

问题

只有正斜杠字符会破坏导致404页面未找到错误的URL.例如,如果我搜索one/twoURL是

http://project_name/browse_by_exam/type/tutor_search/keyword/one%2Ftwo/new_search/1/search_exam/0/search_subject/0/page_sort/
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我需要将index.php隐藏在URL中.否则,如果不需要,那么正斜杠就没有问题了,我可以使用这个URL: -

http://project_name/index.php?browse_by_exam/type/tutor_search/keyword/one
%2Ftwo/new_search/1/search_exam/0/search_subject/0
Run Code Online (Sandbox Code Playgroud)

.htaccess url-rewriting url-encoding http-status-code-404

70
推荐指数
3
解决办法
11万
查看次数

Tomcat在Eclipse中启动但无法连接到http:// localhost:8085 /

我在端口8085上在Eclipse中配置了Tomcat 6.0.24并使用log成功启动,如下所示:

Feb 17, 2010 4:24:31 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;E:\oracle\product\10.2.0\client_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Common Files\Teleca Shared;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;E:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files\MySQL\MySQL Server 5.0\bin;E:\komal-gohil\tools\Subversion\bin;C:\Sun\SDK\bin;e:\instantrails\ruby\bin;c:\program files\java\jdk1.6.0_11\bin;E:\komal-gohil\tools\apache-maven-2.2.1\bin;C:\program files\java\jdk1.6.0_11\bin;E:\komal-gohil\tools\Ant\bin;E:\komal-gohil\tools\apache-tomcat-5.5.17\bin;C:\Sun\SDK\lib\j2ee.jar;E:\komal-gohil\tools\android-sdk-windows-1.6_r1\tools;E:\komal-gohil\tools\Scala\bin;E:\komal-gohil\tools\pax-construct-1.4\bin
Feb 17, 2010 4:24:31 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8085
Feb 17, 2010 4:24:31 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 705 ms
Feb 17, …
Run Code Online (Sandbox Code Playgroud)

eclipse tomcat http-status-code-404

67
推荐指数
1
解决办法
16万
查看次数

TOMCAT - HTTP状态404

我在eclipse中设置我的服务器,当我运行它时控制台打印:

mai 02, 2013 4:05:13 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\Program Files (x86)\Microsoft Application Virtualization Client;c:\Program Files (x86)\Open Text\View\bin;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Java\jre7\bin;C:\WorkspacePPL\apache-maven-3.0.4\bin;.
mai 02, 2013 4:05:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ppl-webapp' did not find a matching property.
mai 02, 2013 4:05:13 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote …
Run Code Online (Sandbox Code Playgroud)

eclipse tomcat http-status-code-404

67
推荐指数
3
解决办法
34万
查看次数

Django Static文件404

我无法得到我的静态文件.我尝试了各种设置和目录配置等等,但它们只是变成404s.我安装了debug_toolbar,因此知道STATIC_URL正在到达我的请求上下文.

目录结构显示/静态(我还将目录放在饭菜app文件夹和用户内部,只是为了试一试.

/mealmate
    /mealmate
    /meals
    /static
        /css
             /bootstrap.min.css
    /templates
    /users
Run Code Online (Sandbox Code Playgroud)

Settings.py(一些重要的设置,虽然我已尝试过各种其他设置):

MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media/')

STATIC_URL = '/static/'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

WSGI_APPLICATION = 'mealmate.wsgi.application'
Run Code Online (Sandbox Code Playgroud)

在base.html中呈现

    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢

django static http-status-code-404

60
推荐指数
11
解决办法
7万
查看次数

找不到JSON文件的错误404.3

即使在我激活了所有"应用程序开发功能"之后,我也在使用"Internet Information Services 7.5"上的AJAX调用来获取JSON文件的"ERROR 404.3 Not Found".除了JSON文件之外,所有其他文件都被加载.

我在本地计算机上的IIS服务器上运行HTML页面.

如果我直接打开文件,那么根本没有问题.当我在在线服务器上托管文件时,它工作正常.

任何快速帮助将不胜感激.

iis json iis-7.5 http-status-code-404 mime-types

60
推荐指数
6
解决办法
5万
查看次数

Laravel 4除主页外的所有路由导致404错误

我使用Composer安装了Laravel 4并设置了虚拟主机.目前,只有根路由正在工作:

<?php

Route::get('/', function()
{
    return View::make('hello');
});
Run Code Online (Sandbox Code Playgroud)

这不是:

Route::get('/hello', function()
{
    return View::make('hello');
});
Run Code Online (Sandbox Code Playgroud)

我试图打是TasksController/tasks:

Route::resource('tasks', 'TasksController');
Run Code Online (Sandbox Code Playgroud)

这也给了我404错误.我能做错什么?我在项目的根目录下有一个默认的.htaccess文件:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我在Mac上使用localhost.

routing http-status-code-404 laravel laravel-4 laravel-routing

59
推荐指数
9
解决办法
6万
查看次数

Phonegap Cordova Ajax请求404(未找到)错误

我的cordova版本是5.0.0

我在设备上部署应用程序时发出的所有ajax请求收到404错误.在Web浏览器上,它工作正常,但在设备上部署时相同的应用程序不起作用.

我尝试添加以下内容来解决问题,但它没有帮助.

config.xml中

<access origin="*" />
Run Code Online (Sandbox Code Playgroud)

AndriodManiest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Run Code Online (Sandbox Code Playgroud)

我还在index.html文件中添加了以下内容,但它也没有任何区别.

<script>
    $.support.cors=true;
</script>
Run Code Online (Sandbox Code Playgroud)

这里的任何人都有另一个解决这个问题的技巧吗?对于phonegap来说似乎是一个非常普遍的问题,但上面的修复工作在phonegap/cordova的旧版本中有效,但在我的情况下没有.

任何帮助都会很棒.

ajax jquery http-status-code-404 cordova

58
推荐指数
2
解决办法
3万
查看次数

如何从Grails控制器返回404/50x状态代码?

我有一个控制器需要在某些条件下返回404页面和状态代码.我似乎无法在Grails中找到如何做到这一点.同事推荐这种方法:

response.sendError(HttpServletResponse.SC_NOT_FOUND)
Run Code Online (Sandbox Code Playgroud)

它的效果非常好,但它并不像Grails那样.我知道Rails的render方法采用status参数,但Grails的render没有这样的功能.有什么我想念的,有什么最好的方法来完成这个?

error-handling grails groovy http-status-code-404

53
推荐指数
4
解决办法
4万
查看次数

Nginx - 自定义404页面

Nginx + PHP(在fastCGI上)对我很有用.当我输入一个不存在的PHP文件的路径时,而不是获取默认的404错误页面(对于任何无效的.html文件来说),我只是得到一个"没有指定输入文件.".

如何自定义此404错误页面?

php nginx http-status-code-404

51
推荐指数
5
解决办法
11万
查看次数