Domanda

All Active folks of StackOverFlow, Greetings for holi (Indian Festival)

I created a simple JDBC program in Eclipse JUNO :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class Connect {
static Connection conn;
public static void main(String[] args) {
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","elt","elt");
        System.out.println("Connected");
    } catch (ClassNotFoundException cnf) {
        cnf.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
}

When I executed this program in Eclipse Juno I got the output :

Connected

But when I created a Java EE project containing a single jsp page and a single servlet, It is giving an error. The code for my JSP page is:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="LoginAction">
    User ID : <input type="text" name="uname"><br><br>
    Password : <input type="password" name="upass"><br><br>
    <input type="Submit" value="submit">
</form>
</body>
</html>

The code for my servlet is as following :

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginAction extends HttpServlet {

static String u_name,u_pass;
static Connection conn;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Hello Foo !");
    u_name = request.getParameter("uname");
    u_pass = request.getParameter("upass");
    out.println(u_name);
    out.println(u_pass);

    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","elt","elt");
        out.println("Connected");
    } catch (ClassNotFoundException cnf) {
        cnf.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
}

The code for My web.xml is :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 <display-name>eLearning</display-name>
 <welcome-file-list>
 <welcome-file>login.jsp</welcome-file>
 </welcome-file-list>
 <servlet>
<servlet-name>LoginAction</servlet-name>
<servlet-class>LoginAction</servlet-class>
 </servlet>
 <servlet-mapping>
<servlet-name>LoginAction</servlet-name>
<url-pattern>/LoginAction</url-pattern>
 </servlet-mapping>
</web-app>

And My Error is :

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at LoginAction.doPost(LoginAction.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Before you start suggesting the source of the error I want to tell you that I have already added the classes12.jar as my normal java program is running. I also have added ojdbc14.jar . I am using oracle 10g.

È stato utile?

Soluzione

Just try to use jdk in place of jre. Use jre6 and tomcat6. JRE7 and TOMCAT7 is not working well in my case dude. So I did what I suggested you. Even the servlet also gets updates with the addition of dependencies.

Altri suggerimenti

classes12.jar is for JDK 1.2/1.3 and ojdbc14.jar is for JDK 1.4/1.5.

If you are using JDK 1.4 or above, then remove classes12.jar from the class path and use only ojdbc14.jar

Hi Friend first you gotta install jdk and then add classes12.jar to your library

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top