• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Why is the servlet not available?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Tomcat error information]
[type] Status report
[message] Servlet tran is not available
[description] The requested resource (Servlet tran is not available) is not available.

[servlet source code]
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Tran extends HttpServlet {

public void init(ServletConfig config)
throws ServletException {
super.init(config);
try {
// Load the driver
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance( );
}
catch (ClassNotFoundException e) {
throw new UnavailableException(
"TransactionConnection.init( ) ClassNotFoundException: " +
e.getMessage( ));
}
catch (IllegalAccessException e) {
throw new UnavailableException(
"TransactionConnection.init( ) IllegalAccessException: " +
e.getMessage( ));
}
catch (InstantiationException e) {
throw new UnavailableException(
"TransactionConnection.init( ) InstantiationException: " +
e.getMessage( ));
}
}

public void doGet(
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter( );
out.println("<html>");
out.println("<head>");
out.println("<title>A Per Transaction Connection</title>");
out.println("</head>");
out.println("<body>");
Connection connection = null;
try {
// Establish a connection
connection = DriverManager.getConnection(
"jdbc racle:thin:@unioninn-jeffma:1521:test", "scott", "tiger");
}
catch (SQLException e) {
throw new UnavailableException(
"TransactionConnection.init( ) SQLException: " +
e.getMessage( ));
}
Statement statement = null;
ResultSet resultSet = null;
String userName = null;
try {
// Test the connection
statement = connection.createStatement( );
resultSet = statement.executeQuery(
"select initcap(user) from sys.dual");
if (resultSet.next( ))
userName = resultSet.getString(1);
}
catch (SQLException e) {
out.println(
"TransactionConnection.doGet( ) SQLException: " +
e.getMessage( ) + "<p>");
}
finally {
if (resultSet != null)
try { resultSet.close( ); } catch (SQLException ignore) { }
if (statement != null)
try { statement.close( ); } catch (SQLException ignore) { }
}
if (connection != null) {
// Close the connection
try { connection.close( ); } catch (SQLException ignore) { }
}
out.println("Hello " + userName + "!<p>");
out.println("You're using a per transaction connection!<p>");
out.println("</body>");
out.println("</html>");
}

public void doPost(
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
doGet(request, response);
}
}

[setting of web.xml]
<servlet>
<servlet-name>tran</servlet-name>
<servlet-class>Tran</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>tran</servlet-name>
<url-pattern>/tran/*</url-pattern>
</servlet-mapping>
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,
I'm always delighted of your warm-hearted commments.
I'll delete this post, which was, indeed, not correct.

"Il n'y a que les imbeciles qui ne se trompent jamais."
Only fools are always right.
Are you ?
[ February 14, 2006: Message edited by: Satou kurinosuke ]
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
Using mappings like "/tran/*" needs the Invoker to be enabled (disabled by default).
Either enable it, or use a more explicit mapping, like "/tran/Tran" (recommended)



That is not correct. There is nothing wrong with that mapping. I use similar mappings all the time.

It's more likely that an exception is being thrown in the init method.
[ February 14, 2006: Message edited by: Bear Bibeault ]
 
Jeff Ma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I move the following code segment to doGet()
try {
// Load the driver
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance( );
}
catch (Exception e) {
throw new UnavailableException(
"TransactionConnection.init( ) Exception: " +
e.getMessage( ));
}

then I found the following information in tomcat logs

2006-02-15 11:26:18 StandardWrapperValve[tran]: Servlet.service() for servlet tran threw exception
javax.servlet.UnavailableException: TransactionConnection.init( ) Exception: oracle.jdbc.driver.OracleDriver
at Tran.doGet(Tran.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
Bear,
I'm always delighted of your warm-hearted commments.



And how approriate for Valentine's Day!


"Il n'y a que les imbeciles qui ne se trompent jamais."
Only fools are always right.
Are you ?



Hardly! "He wept, for he realized that without mistakes, there was nothing left to learn."
 
Jeff Ma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what?


It was about my post
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeff Ma,

From what I see it seems that the error occurs when you try to instantiate the Oracle JDBC driver. Unfortunately, when you catch and re-throw the exception, you lose track of its origin. As a result, lots of information that otherwise might be very helpful in troubleshooting the issue is gone.

What you can do is call the initCause(Throwable t) method to wrap an instance of UnavailableException around the original one:

catch (Exception e) {
UnavailableException ue = new UnavailableException(
"TransactionConnection.init( ) Exception: " +
e.getMessage( ));
ue.initCause(e);
throw ue;
}

or simply re-throw it as a ServletException (which, unlike UnavailableException, has a convenience constructor that takes a Throwable):

catch (Exception e) {
throw new ServletException(
"TransactionConnection.init( ) Exception: " +
e.getMessage( ), e);
}

When you put these changes in place, you will most likely find out that you are getting a ClassNotFoundException. To fix it, make sure your Oracle driver is either under your WEB-INF/lib or somewhere on the classpath.

Oh, and if you are using classes12.zip, some containers may not identify it as a Java archive. Your best bet in this case would be to rename it to something that has a .jar extension, like oracle.jar.

Hope this helps.
 
Jeff Ma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bruno Boehr,thank u very much!

I copy classes12.jar to WEB-INF\lib, that problem is resovled.
And I learn from u the method of debugging.
Thank u!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic