Re: TOmcat 5.0.16 console error,Pls help

2004-02-01 Thread Doug Parsons
Post your HelloServlet code or attach it.


- Original Message - 
From: Avinash Sridhar [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, February 01, 2004 10:21 PM
Subject: TOmcat 5.0.16 console error,Pls help


Hi,
   I was told that the .class files must be put into a package in order for
the tomcat to run it.

My directory structure is as follows,

%TOMCAT HOME %/webapps/sampleapp/WEB-INF/classes
/WEB-INF/lib
/WEB-INF/sourcefiles
/WEB-INF/web.xml
In the classes directory I have make something like this
/classes/package/structure/HelloServlet.class(This is my servlet file),

Now I have changed/made the web.xml in MY WEB-INF directory and have added
this

/ Contents of web.xml file */

?xml version=1.0 encoding=ISO-8859-1?

!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-nameServlet 2.4 Examples/display-name
  description Servlet 2.4 Examples /description

!-- Servlet mapping start --
!-- Define servlets. i.e. bind a servlet name to a class --

servlet
 servlet-nameHelloServlet/servlet-name
  /** This is the prominent change **/
 servlet-classpackage.structure.HelloServlet/servlt-class
  /** This is the prominent change **/

/servlet

!-- bind a servlet name to a URL (pattern) --
servlet-mapping
 servlet-nameHelloServlet/servlet-name
 url-pattern/sampleapp/url-pattern
/servlet-mapping

!-- Servlet mapping end --

/web-app

/ Contents of web.xml file */


Hope that it is right so far,

I dont know how to change the %TOMCAT_HOME%/conf/server.xml,do we have to
change anything here??, this is what I have written in the server.xml file.

/* Contents of server.xml file ***/

Context path=/sampleapp docBase=sampleapp debug=0 reloadable=true
/Context

/* Contents of server.xml file ***/


And finally I am getting theses errors in the tomcat console


/*** Errors in Tomcat console */

Feb 1, 2004 10:04:22 PM org.apache.commons.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 3 column 6: The processing instruction
target
matching [xX][mM][lL] is not allowed.
org.xml.sax.SAXParseException: The processing instruction target matching
[xX]
mM][lL] is not allowed.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(U
known Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown
Source

at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.scanPIData(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanPIData(Unk
own Source)
at org.apache.xerces.impl.XMLScanner.scanPI(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispa
ch(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(U
known Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1548)
at
org.apache.catalina.startup.ContextConfig.applicationConfig(ContextC
nfig.java:302)
at
org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:6
4)
at
org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConf
g.java:254)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecyc
eSupport.java:166)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:
212)
at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1125

at
org.apache.catalina.core.StandardHost.start(StandardHost.java:816)
at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1125

at
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:51
)
at
org.apache.catalina.core.StandardService.start(StandardService.java:
19)
at
org.apache.catalina.core.StandardServer.start(StandardServer.java:23
3)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
sorImpl.java:25)
at 

Re: Re: TOmcat 5.0.16 console error,Pls help

2004-02-01 Thread Doug Parsons
Look at:
http://www.technobuff.net/javatips/kits/startkit/classes_ifs_pkgs.shtml
and
http://cs.stmarys.ca/~porter/csc/465/notes/javapl_packages.html

then check out
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/appdev/deployment.html

This should explain a few things.

- Original Message - 
From: Avinash Sridhar [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Cc: Doug Parsons [EMAIL PROTECTED]
Sent: Sunday, February 01, 2004 11:19 PM
Subject: Re: Re: TOmcat 5.0.16 console error,Pls help


Hi,

  Thanks for the help,The HelloServlet.java file is as follows

/*HelloServlet.java***/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/** Simple servlet used to test server.
 *  P
 *  Taken from Core Servlets and JavaServer Pages 2nd Edition
 *  from Prentice Hall and Sun Microsystems Press,
 *  http://www.coreservlets.com/.
 *  copy; 2003 Marty Hall; may be freely used or adapted.
 */

public class HelloServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
HttpServletResponse response)
  throws ServletException, IOException {
response.setContentType(text/html);
PrintWriter out = response.getWriter();
String docType =
  !DOCTYPE HTML PUBLIC \-//W3C//DTD HTML 4.0  +
  Transitional//EN\\n;

out.println(docType +
HTML\n +
HEADTITLEHello/TITLE/HEAD\n +
BODY BGCOLOR=\#FDF5E6\\n +
H1Hello/H1\n +
/BODY/HTML);
  }
}


/*HelloServlet.java***/

Hoping to get going with it.

Thanks
AS


On Mon, 02 Feb 2004 Doug Parsons wrote :
Post your HelloServlet code or attach it.


- Original Message -
 From: Avinash Sridhar [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, February 01, 2004 10:21 PM
Subject: TOmcat 5.0.16 console error,Pls help


Hi,
I was told that the .class files must be put into a package in order
for
the tomcat to run it.

My directory structure is as follows,

%TOMCAT HOME %/webapps/sampleapp/WEB-INF/classes
 /WEB-INF/lib
 /WEB-INF/sourcefiles
 /WEB-INF/web.xml
In the classes directory I have make something like this
/classes/package/structure/HelloServlet.class(This is my servlet file),

Now I have changed/made the web.xml in MY WEB-INF directory and have added
this

/ Contents of web.xml file */

?xml version=1.0 encoding=ISO-8859-1?

!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-nameServlet 2.4 Examples/display-name
   description Servlet 2.4 Examples /description

!-- Servlet mapping start --
!-- Define servlets. i.e. bind a servlet name to a class --

servlet
  servlet-nameHelloServlet/servlet-name
   /** This is the prominent change **/
  servlet-classpackage.structure.HelloServlet/servlt-class
   /** This is the prominent change **/

/servlet

!-- bind a servlet name to a URL (pattern) --
servlet-mapping
  servlet-nameHelloServlet/servlet-name
  url-pattern/sampleapp/url-pattern
/servlet-mapping

!-- Servlet mapping end --

/web-app

/ Contents of web.xml file */


Hope that it is right so far,

I dont know how to change the %TOMCAT_HOME%/conf/server.xml,do we have to
change anything here??, this is what I have written in the server.xml file.

/* Contents of server.xml file ***/

Context path=/sampleapp docBase=sampleapp debug=0 reloadable=true
/Context

/* Contents of server.xml file ***/


And finally I am getting theses errors in the tomcat console


/*** Errors in Tomcat console */

Feb 1, 2004 10:04:22 PM org.apache.commons.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 3 column 6: The processing instruction
target
matching [xX][mM][lL] is not allowed.
org.xml.sax.SAXParseException: The processing instruction target matching
[xX]
mM][lL] is not allowed.
 at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(U
known Source)
 at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown
Source

 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
 at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
 at org.apache.xerces.impl.XMLScanner.scanPIData(Unknown Source)
 at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanPIData(Unk
own Source)
 at org.apache.xerces.impl.XMLScanner.scanPI(Unknown Source)
 at
org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispa
ch(Unknown Source

Re: servlet gets smtp relay denied error

2003-12-29 Thread Doug Parsons
 When I invoke it from a browser on the same network as the server, it
 works as expected. An email is sent to the specified address, with the
 attachment.

 But when I invoke it from a browser outside of my network, the message
 does not get sent.

I don't have first hand experience in this class, but I got a theory.

One possible problem is that your mail server is not looking at the
connection to determine if it is a relay but at the message.

Have the servlet write out the text of the message to a file or console OR
look at one of the messages sent from inhouse to see how the message is
formed.

Also does/can your mail server send a response to the address attempting the
relay? That could help determine why the mail server thinks it's a relay.


 The mail server is configured to deny relays for anybody not on the LAN,
 but there is no relay request---the servlet runs on the same box as the
 smtp server (which is, in fact, on  the same box as my Apache, Tomcat
 and DNS servers).

 Why does it matter where the browser that sends the request resides?

Now for a real stretch, does your server have a public or private IP
assigned or both?

If both, then consider that the request is being associated with the public
IP when attached from outside and the private when from inside.
If TC is using the public IP in the request to the mail server then is the
mail server set to allow a relay from it's public IP?

I know this might end up being a bunch of fertilizer, but no one had
resonded and every now and then I get lucky.


Good Luck

Doug Parsons
SCJP



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Test

2003-12-23 Thread Doug Parsons
Testing please ignore.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: connection refused, localhost not found

2003-12-08 Thread Doug Parsons
If I read correctly, he said root context still worked. This means the
server is running. What is lost is the ability to move to another context.
Since the standard context are working, it sounds like a typo in the setup.
Learning the details myself, so maybe someone else can narrow the area to
search.

Doug


- Original Message - 
From: Patrick Ale [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Monday, December 08, 2003 7:41 AM
Subject: RE: connection refused, localhost not found


Well,

I got this problem with MLDonkey (not really java, I know but hey.. :P)

This simply means your program crashes on startup and that nothing listens
on port 8080.

Now.. dunno what browser you use but I had this with Mozilla.
I tried to connect to http://localhost:4080/ it didnt find anything on that
port so it
went on with resolving random/known by mozilla things, till it found
localhost.net.au which
actually is an existing page.

Motto of this story is: your app is not running or not on port 8080 :-)

Patrick Ale
System administrator Freeler B.V

Muda o mundo, começe com você mesmo


 -Oorspronkelijk bericht-
 Van: Adam Hardy [mailto:[EMAIL PROTECTED]
 Verzonden: maandag 8 december 2003 13:29
 Aan: Tomcat Users List
 Onderwerp: connection refused, localhost not found


 Hi Listers
 I'm sceptical whether anybody else has ever suffered this bizarre
 problem so I'm not expecting anybody to be able to help, but this is
 seriously damaging my enjoyment of Monday morning.

 I have tomcat 5.0.14 set up on one computer and it works fine mostly,
 i.e. root context, JSP examples, manager apps are working fine.

 The problem is with the app I'm developing. On Friday night
 last week I
 did loads of debugging to sort out the JNDI connection pool, e.g.
 configuring the app context, the web.xml etc.

 Now when I try to call up http://localhost:8080/myapp/ the
 browser zooms
 off to find http://www.localhost.net.au! When I try
 http://127.0.0.1:8080/myapp/ I get a 'connection refused' pop-up from
 the browsers - on my machine and on others. (root context
 still works as
 I said).

 Obviously I tried restarting tomcat, redeploying the app,
 taking out all
 the filters, changing the context name, checked server.xml.

 Anybody care to take a wild guess about what I need to do?

 Tx
 Adam

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



OT: Re: Database pool problem

2003-12-08 Thread Doug Parsons
Everyone has reasons. And some may question our choice. But the goal here is
to help each other. Had he ask which database to use, then I would have
nothing to say. But each of us have conditions which we must work with that
are not under our control. The question of changing databases had already
been asked and he repeated that he could not change. So lets just do our
best to support each other. I don't use MSAccess for mine, but may need to
accomodate the wishes of a client and this information might prove
invaluable at that time. Just my humble opinion.

Doug

P.S. If you wish to flame me you are welcome to do so, just send it to me
directly.




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: newbie help please, localhost not found

2003-12-06 Thread Doug Parsons
You may want to go even more basic than that. Open a command prompt and try
pinging localhost and then try 127.0.0.1  Unless you are running some type
of firewall you should get a response. If not, do you have a personal
firewall enabled?

No you don't have to be connected to a lan, but the TCP/IP stack must be
running. The above test will help you determine that.

If the ping fails you can contact me off list for more help.

I know this veered off topic, but often it is the little things that get ya.



- Original Message - 
From: Jan Behrens [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Saturday, December 06, 2003 11:00 AM
Subject: RE: newbie help please, localhost not found


 Hi there,

 have you tried http://127.0.0.1:8080 instead? That is the IP usually bound
 to localhost and it might be that localhost is not resolved correctly to
 same. If not, try to provide further info. For example, have you installed
 Tomcat in a path containing spaces such as c:\Program Files\Tomcat. If so,
 reinstall to a path without spaces.

 Cheers, Jan

  -Original Message-
  From: D. Gilbert [mailto:[EMAIL PROTECTED]
  Sent: Saturday, December 06, 2003 4:56 PM
  To: Tomcat Users List
  Subject: newbie help please, localhost not found
 
 
  When I type http://localhost:8080 in Internet Explorer it says The page
  cannot be displayed.
  I've looked through the archives but couldn't find anything.
  The running.txt file that comes with Tomcat lists only 3 possibilites
for
  why it doesn't work.
  I've tried changing the port number, I'm using Windows XP so the
  environment
  issue doesn't apply
  and I'm pretty sure that I'm not behind a proxy as I am using my own PC
at
  home.
  I'm pretty sure the JDK is installed ok as I can run javac. I
  tried changing
  JAVA_HOME and CATALINA_HOME to
  incorrect values and that made things worse so I'm sure they are set
  correctly.
  I've tried 2 versions of Tomcat 4.0.1 and 4.1.29.
  When I startup 4.0.1 I get the messages
  
  Starting service Tomcat-Standalone
  Apache Tomcat/4.0.1
  Starting service Tomcat-Apache
  Apache Tomcat/4.0.1
  
  which are correct according to my book.
  Can anyone say what the problem is, or any ways to debug it?
 
  It should run on a standalone home PC shouldn't it? I don't need to be
  connected to a LAN or anything do I?
 
  I've been trying to solve this for 2 weeks now so I would really
  appreciate
  any help please.
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Unclear about JDBC resource def in Tomcat 4.1

2003-12-05 Thread Doug Parsons
 * Any JDBC client webapp can instantiate a driver and get a Connection
 WITHOUT ANY DEFINITION TO THE server.xml or the web.xml as long as the
 driver jars are in /shared/lib or /application/WEB-INF/lib...True or
 False?

True.


 * For convenience, JDBC resources may be be defined to Tomcat as JNDI
 Data Sources to the default JNDI context provided by Tomcat,otherwise no
 config required...True or false?


Not quite. True, no other config is required if you use a connection created
by the application. But this is not a matter of just convenience. It creates
a connection pool from which connections are lent to your application. If
performance is not an issue, you can direct connect. But be aware that pages
will take longer to load due to the time required to establish the
connection with the database each time. Of course you can also use your own
connection pool.

A perfect example is my development platform is XP, but I am deploying to a
RH9 box. I have the Conn class check to see which machine it is on. When on
the server it looks for the JNDI but on XP it does a direct JDBC connection
as my IDE does't know about Tomcat. No other changes are required, just the
one if statement. Being slow in the IDE isn't a problem.

Yeah, I know, more than you asked for.

Doug Parsons
Sun Certified Programmer
Parsons Technical Services Inc.

 Best Regards,

 Michael Dean
 Sun Certified Programmer for the Java 2 Platform
 Washington State Department of Corrections
 ph: 360-664-8802
 fx:  360-664-3985
 mailto:[EMAIL PROTECTED]

 I'm a sailor, of the waters and the sun,
 I can fight the waves but have no weapons for the calm...
 - The Ship



 Best Regards,

 Michael Dean
 Sun Certified Programmer for the Java 2 Platform
 Washington State Department of Corrections
 ph: 360-664-8802
 fx:  360-664-3985
 mailto:[EMAIL PROTECTED]

 I'm a sailor, of the waters and the sun,
 I can fight the waves but have no weapons for the calm...
 - The Ship


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Servlets with JDBC connectivity

2003-12-04 Thread Doug Parsons
This is how I handle mine modified for your application.
import java.sql.*;

public class DBUtil {

/** Retrieves results from query as a DBResults class.

*/

public static DBResults getQueryResults(String query, String dBase) {

Connection connection = Conn.getConn(dBase);

Statement statement = null;

ResultSet resultSet = null;

DBResults dbResults = null;

boolean good = false;

try {

DatabaseMetaData dbMetaData = connection.getMetaData();

String productName = dbMetaData.getDatabaseProductName();

String productVersion = dbMetaData.getDatabaseProductVersion();

statement = connection.createStatement();

resultSet = statement.executeQuery(query);

ResultSetMetaData resultsMetaData = resultSet.getMetaData();

int columnCount = resultsMetaData.getColumnCount();

String[] columnNames = new String[columnCount];

// Column index starts at 1 (a la SQL) not 0 (a la Java).

for (int i = 1; i  columnCount + 1; i++) {

columnNames[i - 1] = resultsMetaData.getColumnName(i).trim();

}

dbResults =

new DBResults(

connection,

productName,

productVersion,

columnCount,

columnNames);

while (resultSet.next()) {

String[] row = new String[columnCount];

// Again, ResultSet index starts at 1, not 0.

for (int i = 1; i  columnCount + 1; i++) {

String entry = resultSet.getString(i);

if (entry != null) {

entry = entry.trim();

}

row[i - 1] = entry;

}

dbResults.addRow(row);

}

good = true;

} catch (SQLException sqle) {

System.err.println(Error connecting:  + sqle);

} finally {

// Always make sure result sets and statements are closed,

// and the connection is returned to the pool

if (resultSet != null) {

try {

resultSet.close();

} catch (SQLException e) {

System.err.println(DataBaseUtilities Error closing resultset:  + e);

}

resultSet = null;

}

if (statement != null) {

try {

statement.close();

} catch (SQLException e) {

System.err.println(DataBaseUtilities Error closing statement:  + e);

}

statement = null;

}

if (connection != null) {

try {

connection.close();

} catch (SQLException e) {

System.err.println(DataBaseUtilities Error closing connection:  + e);

}

connection = null;

}

if (good)

return (dbResults);

else

return (null);

}

}

/** Runs update query.

*/

public static void setUpdate(String query, String dBase) {

Connection connection = Conn.getConn(dBase);

Statement statement = null;

boolean good = false;

try {

statement = connection.createStatement();

statement.executeUpdate(query);

} catch (SQLException sqle) {

System.err.println(Error connecting:  + sqle);

} finally {

// Always make sure statements are closed,

// and the connection is returned to the pool

if (statement != null) {

try {

statement.close();

} catch (SQLException e) {

System.err.println(DataBaseUtilities Error closing statement:  + e);

}

statement = null;

}

if (connection != null) {

try {

connection.close();

} catch (SQLException e) {

System.err.println(DataBaseUtilities Error closing connection:  + e);

}

connection = null;

}


}

}

}



And to handle the data from the resultset that would otherwise be
unaccessable it is places in an DBResults object.

package srm;

import java.sql.*;

import java.util.*;

/** Class to store completed results of a JDBC Query.

* Differs from a ResultSet in several ways:

* UL

* LIResultSet doesn't necessarily have all the data;

* reconnection to database occurs as you ask for

* later rows.

* LIThis class stores results as strings, in arrays.

* LIThis class includes DatabaseMetaData (database product

* name and version) and ResultSetMetaData

* (the column names).

* LIThis class has a toHTMLTable method that turns

* the results into a long string corresponding to

* an HTML table.

* /UL

* P

* Taken from Core Servlets and JavaServer Pages

* from Prentice Hall and Sun Microsystems Press,

* http://www.coreservlets.com/.

* copy; 2000 Marty Hall; may be freely used or adapted.

*/

public class DBResults {

private Connection connection;

private String productName;

private String productVersion;

private int columnCount;

private String[] columnNames;

private Vector queryResults;

String[] rowData;

public DBResults(Connection connection,

String productName,

String productVersion,

int columnCount,

String[] columnNames) {

this.connection = connection;

this.productName = productName;

this.productVersion = productVersion;

this.columnCount = columnCount;

this.columnNames = columnNames;

rowData = new String[columnCount];

queryResults = new Vector();

}

public void addRow(String[] row) {

queryResults.addElement(row);

}

public int getColumnCount() {

return(columnCount);

}

public String[] getColumnNames() {

return(columnNames);

}

public Connection getConnection() {

return(connection);

}

public String getProductName() {

return(productName);

}

public String getProductVersion() {

return(productVersion);

}

public String[] getRow(int index) {

return((String[])queryResults.elementAt(index));

}

public int 

Re: Problems with Tomcat 4.1.27 and MySQL J/Connector 3.0.9 (stable)

2003-12-03 Thread Doug Parsons

Here's my two cent's.

 The problem is that when I try to open the connection by calling method
 dataSource.getConnection() it throws a java.sql.SQLException stating
 Cannot load JDBC driver class 'null'.


Had the same problem on 4.1.29 and 3.23.58
 Try adding this to the Web.xml
servlet-mapping

servlet-nameinvoker/servlet-name

url-pattern/servlet/*/url-pattern

/servlet-mapping



 Server.xml (important parts):
   GlobalNamingResources
 Resource name=jdbc/TestDB auth=Container
   type=javax.sql.DataSource/
 ResourceParams name=jdbc/TestDB
|
|
|
 nameurl/name
 valuejdbc:mysql://localhost/TestDB?autoReconnect=true/value
   /parameter
 /ResourceParams

This section of my code is in a set of context tags.


   /GlobalNamingResources
   Service...
   Engine...
   Realm className=org.apache.catalina.realm.DataSourceRealm
 debug=99 dataSourceName=jdbc/TestDB userTable=UserTBL
 userNameCol=userid userCredCol=pass userRoleTable=RoleTBL
 roleNameCol=role/
   /Engine
   /Service

Not used in my case yet.

Everything else looks like my code. I'm no expert and don't know how most of
it works but it does.

I have one catch on my system. I have to restart Tomcat after I deploy the
war file via manager. I get null pointer exceptions if I don't.

Doug



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Servlets with JDBC connectivity

2003-12-03 Thread Doug Parsons
Based on the how-to and modified for your app:

package yourpackage;

import java.sql.*;

import javax.naming.*;

import javax.sql.*;

public class Conn {

/**Takes desired database as a string and returns a connection.

*/

public static Connection getConn(String dBase) {

Connection connection = null;

String osName = System.getProperty(os.name);

try {

//Start of Tomcat connect

Context ctx = new InitialContext();

if (ctx == null) {

System.err.println(Conn.getConn ctx is null);

throw new Exception(Boom - No Context);

DataSource ds = (DataSource) ctx.lookup(java:comp/env/jdbc/ + dBase);

if (ds != null)

connection = ds.getConnection();

//End of Tomcat connect

} catch (Exception e) {

System.err.println(Conn.getConn  + e);

}

return connection;

}

}



 I think this link over here, might give you a hand.


http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

 There are samples there for databases like mysql, but I think you should
 be ok.


 Todd O'Bryan wrote:

  This may not be the right place to ask this, but if you can direct me
  to the right place, I'd appreciate it.
 
  I'm looking for a design pattern that someone must have already
  thought through so that my head can stop hurting. Here's the problem:
 
  I'm designing a webapp that has several servlets that all access a
  database (or a couple of databases, actually) to either update or
  retrieve information.
 
  Rather than initializing these connections multiple times, dealing
  with SQLExceptions in every class that uses JDBC queries, and
  generally doing things multiple times, I thought I'd put all the
  database stuff into a single class. I created a setUp() method that
  initialized the database connection and then used static methods so I
  could do something like
 
  SQLUtils.executeQuery(a SQL statement);
  SQLUtils.executeUpdate(another one);
 
  anywhere in my webapp. If the database connection had not been
  created, it got created before executing the SQL statement. If it was
  already created, it just got done. I handled all the nastiest
  exceptions in the SQLUtils class, so I didn't have to deal with them
  elsewhere.
 
  You can probably guess the next part. I've discovered I need to
  connect to more than one database, and this design does not support
  that. Creating instances of a SQLUtil class would be a big pain,
  because then I have to pass those around between my servlets and I
  lose one of the huge advantages of this approach, namely a single,
  globally visible interface to the database.
 
  I thought about multiple classes, one for each database I'm connecting
  to, but I know that can't be right on so many levels. Meanwhile, I'm a
  little stumped.
 
  How do people handle this elegantly? The requirements are: a single,
  globally visible (within a webapp) database interface and the ability
  to access multiple databases easily.
 
  Thanks in advance for any ideas,
  Todd
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: forward thing: tomcat 4.1

2003-12-01 Thread Doug Parsons
Kumar,

Why not? There is nothing in the code to stop it from proceeding. Think in
the terms of a servlet. If you called a servlet instead of placing this code
in the jsp, how would you write it. Also do you mean for the (5) statement
to be outside your else bracket? Or did you mean for it to look like this:

if (revList.length  1)
{
req.setAttribute(revList, revList);
   (4)getServletContext().getRequestDispatcher(
/reports.jsp?msg='selectEval'pid= + pid).forward( req, res );
}
else if (revList.length == 1)
{
req.setAttribute(projEvalInfo, pe);
(5)getServletContext().getRequestDispatcher(
/OtaceEvalFormRpt.jsp).forward( req, res );
}

Doug

- Original Message - 
From: Kumar, Sumit [EMAIL PROTECTED]
To: 'Tomcat Users List' [EMAIL PROTECTED]
Sent: Monday, December 01, 2003 11:58 AM
Subject: forward thing: tomcat 4.1


 Hello,

 This is more like a jsp question rather then the tomcat one but pardon me
 for asking here. In my servlet, I do a
 getServletContext().getRequestDispatcher(
 /reports.jsp?msg='selectEval'pid= + pid).forward( req, res ). The code
is
 given below. I believe this should forward it to reports.jsp[line (4)].
But
 what happens is that even though it forwards it to reports.jsp, it
continues
 to execute the servlet even below the forward statement. When it
encounters
 the next forward statement[line (5)], it gives IllegalStateException. I
 would think it should not go even past first forward[line (4)]. Please
help
 in clarifying.

 if (revList.length  1)
 {
 req.setAttribute(revList, revList);
(4)getServletContext().getRequestDispatcher(
 /reports.jsp?msg='selectEval'pid= + pid).forward( req, res );
 }
 else if (revList.length == 1)
 {

 req.setAttribute(projEvalInfo, pe);
 }
 (5)getServletContext().getRequestDispatcher(
 /OtaceEvalFormRpt.jsp).forward( req, res );

 -sumit


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: forward thing: tomcat 4.1

2003-12-01 Thread Doug Parsons
Sorry I read to fast. You are in a servlet. Unless you return or escape out
or try catch it is going to execute to the end or until you do something to
exit.

- Original Message - 
From: Kumar, Sumit [EMAIL PROTECTED]
To: 'Tomcat Users List' [EMAIL PROTECTED]
Sent: Monday, December 01, 2003 11:58 AM
Subject: forward thing: tomcat 4.1


 Hello,

 This is more like a jsp question rather then the tomcat one but pardon me
 for asking here. In my servlet, I do a
 getServletContext().getRequestDispatcher(
 /reports.jsp?msg='selectEval'pid= + pid).forward( req, res ). The code
is
 given below. I believe this should forward it to reports.jsp[line (4)].
But
 what happens is that even though it forwards it to reports.jsp, it
continues
 to execute the servlet even below the forward statement. When it
encounters
 the next forward statement[line (5)], it gives IllegalStateException. I
 would think it should not go even past first forward[line (4)]. Please
help
 in clarifying.

 if (revList.length  1)
 {
 req.setAttribute(revList, revList);
(4)getServletContext().getRequestDispatcher(
 /reports.jsp?msg='selectEval'pid= + pid).forward( req, res );
 }
 else if (revList.length == 1)
 {

 req.setAttribute(projEvalInfo, pe);
 }
 (5)getServletContext().getRequestDispatcher(
 /OtaceEvalFormRpt.jsp).forward( req, res );

 -sumit


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]