The glaring error is that you've called the method dopost, when it should be doPost
(not the
capital) to override the superclass's method.
Simon
Sam Rose wrote:
> 'Based upon the code in Jason Hunters book'.
>
> I'm not sure why this isn't working, the error that brings up when
> running the servlet (compiles fine) is,
>
> 400 post is not supported by this url 69.
>
> Would it be something to do with the fact that I'm redirecting to
> another servlet?
>
> import java.io.*;
> import java.util.*;
> import java.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> /*
> A servlet to login the users.
> Redirects to a protected page, if it is accessed before logging in.
> Available to all DBowner types.
> */
>
> public class login extends HttpServlet {
>
> public void init(ServletConfig config) throws ServletException {
> super.init(config);
> try {
> Class.forName( "oracle.jdbc.driver.OracleDriver" );
> }
> catch (java.lang.ClassNotFoundException e) {
> throw new UnavailableException(this, "Couldn't load Oracle
> Driver");
> }
> }
>
> public void dopost (HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
>
> res.setContentType("text/html");
> PrintWriter os=res.getWriter();
>
> //Gets the parameters
> String user= req.getParameter("User");
> String passwd=req.getParameter("Password");
>
> //Sets up the connection, statement, and resultsets
> String url = "jdbc:oracle:thin:@computer:1521:orcl";
> Connection con=null;
> Statement stmt=null;
> ResultSet Downer=null;
>
> String DBowner = (("Select ROLE from sam.DBOWNERS WHERE USERNAME =
> '") + user + ("'"));
>
> try {
> con = DriverManager.getConnection( url, user, passwd );
> stmt = con.createStatement();
> //valid login
> HttpSession session=req.getSession(true);
> Downer = stmt.executeQuery(DBowner);
> String DBownertype=null;
> while (Downer.next()) {
> DBownertype = Downer.getString("ROLE");
> }
> session.putValue("logon.isDone", user); // just a marker
>object
> session.putValue("login.user", user);
> session.putValue("login.password", passwd);
> session.putValue("login.DBownertype", DBownertype);
>
> // Try redirecting the client to the page he first tried to access
> try {
> String target = (String)
>session.getValue("login.target");
> if (target != null)
> res.sendRedirect(target);
> return;
> }
> catch (Exception ignored) { }
>
> // Couldn't redirect to the target. Redirect to the site's home
> page.
> String dblogin = ("HTTP://tb187.info.bt.co.uk/vdb/dblogin");
> res.sendRedirect(dblogin);
>
> }
> catch(SQLException ex) {
> //invalid login
> os.println("<HTML><HEAD><TITLE>Access
>Denied</TITLE></HEAD>");
> os.println("<BODY>Your login and password are
> invalid.<BR>");
> os.println("You may want to <A HREF=\"/login.html\">try
> again</A>");
> os.println("</BODY></HTML>");
> }
>
> finally {
> try {
> if (con != null) con.close();
> if (stmt != null) stmt.close();
> if (Downer !=null) Downer.close();
> }
> catch (SQLException ignored) {}
> }
> os.flush();
> }
>
> public void destroy() {
> super.destroy();
> }
> }
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html