Having nightmare configuring server.xml


I have a server.xml file that I need to configure to get my jsp pages fetching data from mysql database. My Server is apache/tomcat 5.5.16 and MySQL version is 5.0. The connector .jar for MySQL is in place. Now I have to configure <Context> tag in server.xml for MySQL and also for each class name has to be defined via the server.xml.

I have 23 .class files on the server and the following in my <Host> tag in server.xml

<Host name="www.nichefhgs.com" appBase="/www/virtual/mja/www.nichefhgs.com"
        unpackWARs="true" autoDeploy="true">

        <Context path="" docBase="" debug="0" reloadable="true"/>

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="web1_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>

Please help, it has been a nightmare for me.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
you could just build a war, and avoid touching server.xml all together

or in server.xml your context would look something like:

<Context path="/DBTest" docBase="DBTest"
        debug="5" reloadable="true" crossContext="true">

    <!-- maxActive: Maximum number of dB connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to 0 for no limit.

    <!-- maxIdle: Maximum number of idle dB connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.

    <!-- maxWait: Maximum time to wait for a dB connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.

    <!-- username and password: MySQL dB username and password for dB connections  -->

    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
    <!-- url: The JDBC connection url for connecting to your MySQL dB.
         The autoReconnect=true argument to the url makes sure that the
         mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
         connection.  mysqld by default closes idle connections after 8 hours.

  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"


taken from http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
n2alexanAuthor Commented:
even if I have a class that connects to the database and this class is used for all my sql data reading and writing I would still have to add what you have suggested.

public class Connector {
    /** Creates a new instance of Connector */
    public Connector() {
    private String dbUrl = "jdbc:mysql://localhost:3306/mydatabasename";
    private String jdbcDriver = "com.mysql.jdbc.Driver";
    public Connection getConnection() {
        Connection con = null;
        try {
            con = DriverManager.getConnection(dbUrl, "someuser", "somepassword");
        } catch (SQLException se) {
            System.err.print("getConnection SQLException: " + se.toString());
        } catch (ClassNotFoundException cnfe) {
            System.err.print("getConnection ClassNotFoundException: " + cnfe.toString());
        return con;
n2alexanAuthor Commented:
Also, my host told me that there's no auto deployment and
each class name has to be defined via the server.xml. I have 23 .class files. What should I do about this?

Thank you for you help.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Mick BarryJava DeveloperCommented:
no, to do that you would not need anything specific in your server.xml.
you'd just need to add the driver jar to your webapp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mick BarryJava DeveloperCommented:
> each class name has to be defined via the server.xml. I have 23 .class files. What should I do about this?

not sure what they meant.
u sure they didn't mean each *context* would need to be defined?
n2alexanAuthor Commented:
how do I add the driver jar to my webapp?
n2alexanAuthor Commented:
For my questions to the host "Did I place my .class files in the correct directory? (WEB-INF/classes)"
the host replied

the host replied with this:
"there's no auto deployment each class name has to be defined via the server.xml under the virtualhost for www.nichefhgs.com"

I thought that it means that each class files must be somehow declared in server.xml.

And I am not sure how to do it?

Many thanks for help
Mick BarryJava DeveloperCommented:
either put them in <tomcat>/common/lib to make them available to all webapps

or put them in <webapp>/WEB-INF/lib
Mick BarryJava DeveloperCommented:
> "there's no auto deployment each class name has to be defined via the server.xml under the virtualhost for www.nichefhgs.com"

i think they meant each *context* has to be defined in server.xml
n2alexanAuthor Commented:
ok I have created /WEB-INF/lib directory and copied my framework/<class files> there, where framework is my package name (actually I do not have webapp directory on my server and instead I have to put everything in /www/virtual/mja directory.)
n2alexanAuthor Commented:
But it is not working
Mick BarryJava DeveloperCommented:
just jars should go in WEB-INF/lib
classes goo in WEB-INF/classes

When I say <webapp> I am referring to whatever directory your web application is in, sorry that wasn't clear
n2alexanAuthor Commented:
I have checked <tomcat>/common/lib directory and it contains mysql-connector-java-3.1.12-bin.jar which is Connector J
n2alexanAuthor Commented:
And if I understand correctly I do not need to place this file in WEB-INF/lib directory for my Web Application.
Mick BarryJava DeveloperCommented:
>  And if I understand correctly I do not need to place this file in WEB-INF/lib directory for my Web Application.

n2alexanAuthor Commented:
I have just created simple jsp page (I used the correct login values for db, username and password).


<%@ page import="java.sql.*" %>
String connectionURL = "jdbc:mysql://localhost/somedb?user=someuser;password=somepassword";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;


connection = DriverManager.getConnection(connectionURL, "", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM cat");

while (rs.next()) {




which when I call gives me this org.apache.jasper.JasperException: Exception in JSP: /testdb.jsp:13

11: <%
12: Class.forName("com.mysql.jdbc.Driver").newInstance();
13: connection = DriverManager.getConnection(connectionURL, "", "");
14: statement = connection.createStatement();
15: rs = statement.executeQuery("SELECT * FROM category");


root cause

javax.servlet.ServletException: Access denied for user ''@'' (using password: NO)

Do you have any idea what is going on here?

n2alexanAuthor Commented:
I use the same credentials to login into phpMyAdmin
n2alexanAuthor Commented:
The main reason why I used this page to test is that it does not use any java beans.
This will eliminate that problem and just concentrate on connection.

Many many thanks for your help.
Mick BarryJava DeveloperCommented:
looks like you don't have access to mysql.
do you need to provide user/password?
Mick BarryJava DeveloperCommented:
> connection = DriverManager.getConnection(connectionURL, "", "");

supply the user/pass here

connection = DriverManager.getConnection(connectionURL, "someuser", "somepass");
n2alexanAuthor Commented:
Dear object,

You were right. I do not need anything in server.xml. My host had resolved the issue by changing persmissions for root for 127.

Thank you for your help,
Mick BarryJava DeveloperCommented:
no worries :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.