I'm running JRun 3.0, on Win2K and I'm having a problem getting this servlet to run. I know I've put the servlet in the right directory, since I was able to successfully run a simple "Hello World" servlet.
I'm assuming there's something wrong with my servlet specific code, since the main method I've written works with no problems. (the main method is just cut and paste from the doGet, but without the javax.servlet classes)
here's the code, I really hope you can help me:
leo
------------
Leo Mendoza
lmendoza-at-garbersoft-dot-net
I'm assuming there's something wrong with my servlet specific code, since the main method I've written works with no problems. (the main method is just cut and paste from the doGet, but without the javax.servlet classes)
here's the code, I really hope you can help me:
Code:
/**
* CCTAdmin.java
* Used as a wrapper class, to allow
* users with priviledges to authenticate against a DB and
* modify information contained within. The class handles all requests
* made for administration
**/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
class CCTAdmin extends HttpServlet {
private Connection c = null;
private Statement s = null;
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//first we authenticate the session against what's in the DB
HttpSession sess = req.getSession();
if(sess.getAttribute("login.userName") != null) { //1st layer of verification
res.setStatus(res.SC_UNAUTHORIZED); //not valid, page not found
return;
} //end if
String sql = "SELECT userid FROM CCT_AuthUsers WHERE UserLogin = '" +
sess.getAttribute("login.userName") + "' AND sid = '" + sess.getId() + "'";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection(
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Site Mirror/test.mdb",
"","");
s = c.createStatement();
ResultSet rs = s.executeQuery(sql);
if(!rs.next()) {
res.setStatus(res.SC_UNAUTHORIZED);
return;
} //end if
//once we get here, we're validated and authorized
int atype = Integer.parseInt(req.getParameter("atype"));
} catch (ClassNotFoundException e) {
System.out.println("Class not found!\n" + e.getMessage() + "\n" + e.toString());
} catch (SQLException e) {
System.out.println("SQL Error occurred!\n" + e.getMessage() + "\n" + e.toString());
} finally {
try {
if(c != null) c.close();
} catch (Throwable t) {
System.out.println("Could not close connection");
} //end try
} //end try
} //end doPost
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req,res);
} //end doGet
/**
* to test features
**/
public static void main (String [] args) {
CCTAdmin c = new CCTAdmin();
c.dodb();
} //end main
private void dodb() {
Connection ct = null;
Statement st = null;
//first we authenticate the session against what's in the DB
String sql = "SELECT userid FROM CCT_AuthUsers WHERE UserLogin = '" +
"leo" + "' AND sid = 12";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
ct = DriverManager.getConnection(
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Site Mirror/test.mdb",
"","");
st = ct.createStatement();
ResultSet rs = st.executeQuery(sql);
if(!rs.next()) {
System.out.println("invalid");
return;
} //end if
//once we get here, we're validated and authorized
int atype = Integer.parseInt("12");
} catch (ClassNotFoundException e) {
System.out.println("Class not found!\n" + e.getMessage() + "\n" + e.toString());
} catch (SQLException e) {
System.out.println("SQL Error occurred!\n" + e.getMessage() + "\n" + e.toString());
} finally {
try {
if(ct != null) ct.close();
} catch (Throwable t) {} //end try
} //end try
} //end main
} //end CCTAdmin
------------
Leo Mendoza
lmendoza-at-garbersoft-dot-net