Tim,
I'm doing everything you suggest below with the exception of having the
classes in a package (JRUN is not finding them. For example, if I name the
package "net.dirtroad," placing the class files in
/WEB-INF/classes/net/dirtroad throws a ClassNotFoundException and Forte
reports an "Invalid package name" error). I don't know what's up with this
(I'm new to JRUN), so I just used the default package. Now this was working
if I took the database field values and set them into session scope as
attributes and then set the Bean properties from the JSP page using the
session.getAttribute() values, but I cannot get the servlet to set the Bean
properties and then read them from the JSP. Here's the program flow (and
BTW, you are right on the general architecture):
JSP logon >> Controller servlet >> Authenticate servlet (get values from
database) >> JavaBean set >> Controller >> appropriate JSP based on
accesslevel << JavaBean get.
I tried to send the code, but the listserv reject anything over 300 lines.
Below is just my Authenticate.java that attempts to set the Bean properties.
I don't blame anyone for not wanting to look at my shitty code!
public class Authenticate extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
protected void processRequest(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException {
HttpSession session = req.getSession();
if( session == null) {
res.sendError( res.SC_PRECONDITION_FAILED, "Session has not been
instantiated.");
}
Integer accessCount = new Integer( 0);
if( !session.isNew()) {
Integer oldAccessCount = (Integer) session.getAttribute(
"accessCount");
if( oldAccessCount != null) {
accessCount = new Integer( oldAccessCount.intValue() + 1);
}
}
session.setAttribute( "accessCount", accessCount);
String parmUserid = req.getParameter( "userid");
String parmPW = req.getParameter( "password");
if( parmUserid.trim().length() > 0 && parmPW.trim().length() > 0) {
UserBean userBean = new UserBean();
Calendar ts = Calendar.getInstance();
String time = ts.getTime().toString();
String sql = "SELECT * FROM validation.dbo.gatekeeper";
String dbURL = "jdbc:microsoft:sqlserver://CC615520-C:1433";
String minit = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection(
dbURL,"sa","rocket01");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( sql);
while( rs.next()) {
String id = rs.getString( "email");
String pw = rs.getString( "passwd");
if( parmUserid.equalsIgnoreCase( id) &&
parmPW.equalsIgnoreCase( pw)) {
String fname = rs.getString( "fname");
if( rs.getString( "minit") != null) { minit =
rs.getString( "minit");}
String lname = rs.getString( "lname");
String accesslevel = rs.getString( "accesslevel");
String lastaccess = rs.getString( "lastaccess");
userBean.setUserID( id);
userBean.setPassword( pw);
userBean.setFname( fname);
if( minit != null) {
userBean.setMinit( minit);
}
userBean.setLname( lname);
userBean.setAccessLevel( accesslevel);
userBean.setLastAccess( lastaccess);
String updateSQL = "UPDATE validation.dbo.gatekeeper
SET lastaccess='" + time + "' WHERE email='" + parmUserid + "'";
stmt.executeUpdate( updateSQL);
conn.commit();
conn.close();
RequestDispatcher rd =
getServletContext().getRequestDispatcher( "/servlet/Controller");
if( rd != null) {
rd.forward( req, res);
} else {
res.sendError( res.SC_NOT_FOUND, "The Controller
is not available.");
}
}
}
} catch( ClassNotFoundException e) {
e.printStackTrace();
} catch( SQLException e) {
e.printStackTrace();
}
RequestDispatcher rd =
getServletContext().getRequestDispatcher( "/newUser.jsp?userid=" +
parmUserid);
if( rd != null) {
rd.forward( req, res);
} else {
res.sendError( res.SC_NOT_FOUND, "The requested resource was
not available.");
}
} else {
int cnt = 0;
try {
cnt = Integer.parseInt( session.getAttribute(
"accessCount").toString());
} catch( NumberFormatException e) {
e.printStackTrace();
}
if( cnt < 3) {
RequestDispatcher rd =
getServletContext().getRequestDispatcher( "/index.jsp?error=true");
if( rd != null) {
rd.forward( req, res);
} else {
res.sendError( res.SC_NOT_FOUND);
}
} else {
session.invalidate();
res.sendError( res.SC_UNAUTHORIZED, "You have exhausted your
login attempts. Please contact the system administrator.");
}
}
}
___________________________________________________________________________
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