Question everyone!!!!!!
              Quick background and then the question.  I am doing a
redirect to an html page(index.html) after a username and login has been
validated.  The redirect works fine except that the new page is being
displayed in the middle frame of the index.html.  Is there a way that I
can, in my servlet code, dispose of the index.html file and have only
the file(home.html frame) I am redirecting be the one displayed?  Please
see code below.

Cheers

Pat


//imports java servlet libraries
import javax.servlet.*;
import javax.servlet.http.*;

//imports libraries
import java.util.*;
import java.io.*;
import java.sql.*;

public class LoginTest extends HttpServlet {

     public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
   {
        doPost(req,res);
   }

   public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {

      PrintWriter out = res.getWriter();
      res.setContentType("text/html");

      String Uname = req.getParameter("username");
      String Upasswd = req.getParameter("userpasswd");

      if ( req.getParameter("username").equals("") ||
req.getParameter("userpasswd").equals(""))
           {
         out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");

         out.println("<BODY>Your login and password are invalid.<BR>");
         out.println("You may want to
<A>HREF=http://barney:8080/index.html>try again</A>");
         out.println("</BODY></HTML>");
      }
       else if ( !req.getParameter("username").equals("") &&
                 !req.getParameter("userpasswd").equals(""))
       {
                boolean isValidUser = validateUser(Uname,Upasswd);
                if ( isValidUser ) {
                    //IT IS A SUCCESS DO THE REDIRECT HERE....

res.sendRedirect("http://barney:8080/text/app/home.html");
                }
                else
                {
                   //FAILED RETURN MESSAGE TO USER
                    out.println("<p> User Validation Failed for User: "
+ Uname);                                }
                }

 }
 public boolean validateUser(String username, String userpassword)
 {
         String dbuserid = "";
         String dbpasswd = "";
         boolean isValidUser = false;
         try
            {
                Class.forName("oracle.jdbc.driver.OracleDriver");
            }
                catch(java.lang.ClassNotFoundException e)
                {
                  System.err.print("ClassNotFoundException:");
                  System.err.println(e.getMessage());
       }

         try
           {
           //DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
           Connection conn = DriverManager.getConnection(
           "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS="+
           "(PROTOCOL = TCP)(HOST = fred)"+
           "(PORT = 1521)))(CONNECT_DATA = (SID =ORA)))",
           "dev_user","dev_user");

           // Create a Statement and create a query string!
             String query = "SELECT  USERNAME, PASSWORD FROM USERLOGIN"
+
                            " where USERNAME = '" + username +
                            "' and PASSWORD = '" + userpassword + "'";
                  Statement stmt = conn.createStatement();
                  ResultSet rst = stmt.executeQuery(query);

               if (rst.next()) {
               dbuserid = rst.getString(1);
               dbpasswd = rst.getString(2);
             }
             if ( username.equals(dbuserid.trim()) &&
userpassword.equals(dbpasswd.trim()) )
             {
                 //We have a successful match of input userid and
                 //password with a database rec.
                 isValidUser = true;
                } else {
                        //we did not succeed
                        isValidUser = false;
                }

            stmt.close();
            conn.close();
           } catch(SQLException ex) {
                System.out.println("SQLException: " + ex.getMessage());
           }
           return isValidUser;
          }
        }

___________________________________________________________________________
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

Reply via email to