0

There are similar questions I've found, for example here and here but in both of them, results are being printed in the console while in my case, there's nothing.

The issue is, I have a Java Servlet subclass that I would like to print something to the browser screen. However, when I go the url the servlet is mapped to, it prints this to the screen:

Apache Tomcat 405

This is my Servlet subclass:

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;
    }
}   

and this is my 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>

When I run the server, this is what the console prints out:

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
Community
  • 1
  • 1
CodyBugstein
  • 17,496
  • 50
  • 159
  • 312

2 Answers2

0

Seems there was an error in my web.xml file. Things started working better when I changed the header of my web.xml file from

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

to

<?xml version="1.0" encoding="UTF-8" ?>
CodyBugstein
  • 17,496
  • 50
  • 159
  • 312
0

You have not org.postgresql.Driver in apache.

Choose your jdbc.jar

  1. JDBC3 Postgresql Driver, Version 9.3-1102
  2. JDBC4 Postgresql Driver, Version 9.3-1102
  3. JDBC41 Postgresql Driver, Version 9.3-1102

Add jdbc-version.jar to apache-tomcat-x.x.x\lib file.

hurricane
  • 5,592
  • 2
  • 28
  • 39