此 URL 不支持 HTTP 方法 GET - 没有打印到控制台
Posted
技术标签:
【中文标题】此 URL 不支持 HTTP 方法 GET - 没有打印到控制台【英文标题】:HTTP method GET is not supported by this URL - nothing printing to console 【发布时间】:2014-10-24 23:42:24 【问题描述】:我发现了类似的问题,例如here 和here,但在这两个问题中,结果都打印在控制台中,而在我的情况下,什么都没有。
问题是,我有一个 Java Servlet 子类,我想在浏览器屏幕上打印一些东西。但是,当我转到 servlet 映射到的 url 时,它会将其打印到屏幕上:
这是我的 Servlet 子类:
package instrurental_proj.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Bla extends HttpServlet
private static final long serialVersionUID = 16252534;
private static int ping = 3000;
private Thread t;
private static boolean shouldStop = false;
@Override
public void init() throws ServletException
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
System.out.println("doGet");
PrintWriter out = resp.getWriter();
out.println("<html><h1>It works!!</h1></html>");
@Override
public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException
System.out.println("service");
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
System.out.println("doPost");
@Override
public void destroy()
System.out.println("Destroy servlet");
shouldStop = true;
这是我的web.xml
:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Bla</servlet-name>
<servlet-class>instrurental_proj.servlets.Bla</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Bla</servlet-name>
<url-pattern>/bla</url-pattern>
</servlet-mapping>
</web-app>
当我运行服务器时,这是控制台打印出来的:
Aug 31, 2014 12:50:36 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:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\ActiveState Komodo Edit 8\;C:\Program Files (x86)\Haskell\bin;C:\Program Files (x86)\Haskell Platform\2013.2.0.0\lib\extralibs\bin;C:\Program Files (x86)\Haskell Platform\2013.2.0.0\bin;C:\Program Files (x86)\HP SimplePass\x64;C:\Program Files (x86)\HP SimplePass\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;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\jdk1.7.0_25\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files (x86)\PostgreSQL\9.3\lib;C:\Program Files\SourceGear\Common\DiffMerge\;C:\Program Files (x86)\QuickTime\QTSystem;C:\Python27\;C:\Python27\Scripts;C:\Program Files (x86)\Haskell Platform\2013.2.0.0\mingw\bin;C:\Anaconda;C:\Anaconda\Scripts;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\VisualSVN Server\bin;C:\wamp\bin\php\php5.4.12;C:\ProgramData\ComposerSetup\bin;C:\Program Files (x86)\Boundless\OpenGeo\bin;C:\Program Files (x86)\Boundless\OpenGeo\jetty\jre\bin;C:\Program Files\Java\jdk1.7.0_25;C:\Users\Imray\AppData\Roaming\cabal\bin;C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Google\google_appengine\;C:\Program Files (x86)\Apache Software Foundation\apache-maven-3.2.3\bin;.
Aug 31, 2014 12:50:36 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]Server/Service/Engine/Host/Context Setting property 'source' to 'org.eclipse.jst.j2ee.server:instrurental_proj' did not find a matching property.
Aug 31, 2014 12:50:36 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Aug 31, 2014 12:50:36 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Aug 31, 2014 12:50:36 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 465 ms
Aug 31, 2014 12:50:36 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 31, 2014 12:50:36 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Aug 31, 2014 12:50:36 PM org.apache.catalina.realm.JDBCRealm startInternal
SEVERE: Exception opening database connection
java.sql.SQLException: org.postgresql.Driver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:692)
at org.apache.catalina.realm.JDBCRealm.startInternal(JDBCRealm.java:780)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5350)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:688)
... 11 more
Aug 31, 2014 12:50:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Aug 31, 2014 12:50:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Aug 31, 2014 12:50:38 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1617 ms
【问题讨论】:
您确定向我们展示了正确的配置和 servlet 吗?您发布的代码无法给出 405。 @SotiriosDelimanolis 是的,100% 确定 嗯...我没看到。打开您的容器日志并向我们展示它打印的内容。 在哪里可以找到容器日志?你是说控制台吗? 是的,我指的是控制台。 apache tomcat的日志在安装目录/logs
下。
【参考方案1】:
你在 apache 中没有 org.postgresql.Driver。
选择你的 jdbc.jar
-
JDBC3 Postgresql Driver, Version 9.3-1102
JDBC4 Postgresql Driver, Version 9.3-1102
JDBC41 Postgresql Driver, Version 9.3-1102
将 jdbc-version.jar 添加到 apache-tomcat-x.x.x\lib 文件中。
【讨论】:
【参考方案2】:我的web.xml
文件中似乎有错误。当我从
web.xml
文件的标题时,事情开始变得更好
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
到
<?xml version="1.0" encoding="UTF-8" ?>
【讨论】:
以上是关于此 URL 不支持 HTTP 方法 GET - 没有打印到控制台的主要内容,如果未能解决你的问题,请参考以下文章
此 URL 不支持带有简单 servlet 的 HTTP 方法 GET
Apache Tomcat HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET [重复]
简单 Servlet HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET [重复]
HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET
此 URL 不支持 HTTP 方法 GET,尽管它执行 doGet [重复]
HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET - RequestDispatcher 出现错误