HTTP状态404 - / DatabaseAccess说明请求的资源不可用

时间:2015-02-13 09:09:05

标签: java mysql jsp servlets

我写了一个程序来访问数据库但是我试图运行它但是它给了我一些错误请帮忙:

这是我的user3.html

<html>
<body bgcolor="green">
<center>
<h1>Demo </h1>
<form action="/DatabaseAccess" method="post">
<input type="submit" value="submit">
</form>
</center>
</body>
</html>

这是web.xml

  <web-app>
  <servlet>
  <servlet-name> DatabaseAccess</servlet-name>
  <servlet-class>DatabaseAccess</servlet-class>

  </servlet>
  <servlet-mapping>
    <servlet-name>DatabaseAccess</servlet-name>
     <url-pattern>/DatabaseAccess</url-pattern>
   </servlet-mapping>
   </web-app>

这是我的javafile DatabaseAccess.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

 public class DatabaseAccess extends HttpServlet
 {
     public void doPost(HttpServletRequest request,HttpServletResponse    response) throws ServletException, IOException
      {
       // JDBC driver name and database URL

    final String JDBC_DRIVER="sun.jdbc.odbc.JdbcOdbcDriver";  
        final String DB_URL="jdbc:oracle:thin:SYSTEM@localhost:1522:ORCL";

      //  Database credentials

    final String USER = "SYSTEM";
        final String PASS = "BusinessAnalysis";

     // Set response conntent type

    response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String title = "Database Result";
    String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " +  "transitional//en\">\n";
        out.println(docType +  "<html>\n" + "<head><title>" + title + "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n" +
                "<h1 align=\"center\">" + title + "</h1>\n");
        try
    {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:ORACLE_DSN", "SYSTEM", "BusinessAnalysis");
         Statement stmt = con.createStatement();

                           // send a SQL query to retrieve records
            ResultSet res = stmt.executeQuery("select * from praveen");
                                            // process the data
            while(res.next())
            {
                System.out.println(res.getInt("rno") + "\t" + res.getInt("age"));
            }
                                            // close the database connection
         res.close();
            stmt.close();
            con.close();
        }
            catch(SQLException se)
    {
            //Handle errors for JDBC
            se.printStackTrace();
        }
    catch(Exception e)
    {
            //Handle errors for Class.forName
            e.printStackTrace();
        }

   }
} 

我收到HTTP状态404- / DatabaseAccess的错误               描述:请求的资源不可用

帮助将不胜感激!!

0 个答案:

没有答案