Form>
Center>
Body>
Html>
Note: ServletContext is Web Context, Flightalias is Component AliaSes
3. The servlet code is as follows: (Flight.java)
Import javax.servlet. *;
Import javax.servlet.http. *;
Import java.io. *;
Import java.util. *;
Import java.sql. *;
Public Class Flight Extends Httpservlet
{
Connection DBCON;
PREPAREDSTATEMENT S;
ResultSet Result;
Public Void Service (httpservletRequest Req, httpservletResponse res) throws oException
{
//Connect to the database
Try
{
Class.Forname ("Sun.jdbc.odbc.jdbcodbcdriver");
DBCON = DriverManager.getConnection ("JDBC: ODBC: MyDataSource", "SA", "");
}
Catch (ClassNotFoundException E)
{
System.out.println ("Database Driver Not Found");
System.out.println (E.TOString ());
}
Catch (Exception E)
{
System.out.println ("unknown !?");
} // end catch
// boolean cookiefound = false;
Boolean valuefound = false;
// cookie thiscookie = NULL;
String Numid = Req.getParameter ("NUMID");
String password = Req.getParameter ("password"); string fromcity, Tocity;
"fromcity = new string ();
Tocity = new string ();
Res.SetContentType ("text / html");
PrintWriter out = res. maxwriter ();
/ * Cookie [] cookies = req.getCookies ();
Try
{
For (int i = 0; i
{
System.out.Println ("Inside for");
thiscookie = cookies [i];
IF (thiscookie.getname (). Equals ("pnrnum"))
{
System.out.println ("Cookie Found");
CookiefOnd = true;
Break;
}
}
}
Catch (NullpointersException E)
{
Cookiefound = false;
} * /
Try
{
s = dbcon.preparestatement ("SELECT * FROM FLIGHT WHERE NUMID =?");
S.setString (1, NumID);
Result = S.ExecuteQuery ();
IF (result.next ())
{
Valuefound = true;
//System.out.println (Result.getstring(0));
}
Else
{
Valuefound = false;
} // END ELSE
} // end try
Catch (Exception E)
{
System.out.println (E.TOString ());
}
IF (valuefound == true)
{
Out.println ("");
Out.println ("
");
Out.println ("The Booking Details Are As Follows / N");
Out.println ("
");
Try
{
Try
{
FromCity = Result.getstring (2);
Tocity = Result.getstring (3);
}
Catch (Exception E)
{
System.out.println ("Error");
System.out.println (E.TOString ());
}
Out.println ("
");
Out.println ("
");
Out.println ("from city:");
Out.println (" TD>");
Out.println (" | ");
Out.println (fromCITY);
Out.println (" TD>");
Out.println (" TR>");
Out.println (" |
");
Out.println ("
");
Out.println ("To City:");
Out.println (" td>"); out.println (" | ");
Out.println (Tocity);
Out.println (" TD>");
Out.println (" TR>");
}
Catch (Exception EV)
{
System.out.println ("Error");
}
} // end if
IF (valuefound == false)
{
Out.println ("The Number ID That You Have Specified Does Not Exist.");
Out.println ("please check if you have entered the correct number ID.");
} // end if
Try
{
dbcon.close ();
}
Catch (Exception E)
{
System.out.Println ("Error Closing Database");
}
} // End Service
}
4. Launch the J2EE server After the client browser is entered http://127.0.0.1:8000/servletContext/login.html
转载请注明原文地址:https://www.9cbs.com/read-122633.html
|