Compass Travel J2EE application
81
String
firstName="";
String lastName="";
String sql= "SELECT password, first_name, last_name FROM user WHERE user_id=?";
Connection connection=null;
PreparedStatement ps=null;
ResultSet rs=null;
boolean validLogon=false;
try {
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource) ctx.lookup("compass");
connection=ds.getConnection();
ps=connection.prepareStatement(sql);
ps.setString(1, userId);
rs = ps.executeQuery();
if (rs.next()) {
if (password.equals(rs.getString("password"))) {
validLogon=true;
firstName=rs.getString("first_name");
lastName=rs.getString("last_name");
}
}
} catch (Exception e) {
System.out.println(e);
throw new ServletException(e);
} finally {
try {
rs.close();
ps.close();
connection.close();
} catch (Exception e) {
System.out.println(e);
}
}
if (validLogon) {
HttpSession session = request.getSession();
session.setAttribute("userId", userId);
session.setAttribute("firstName", firstName);
session.setAttribute("lastName", lastName);
response.sendRedirect(validLogonPage);
} else {
response.sendRedirect(invalidLogonPage);
}
}
}
2 Save the file as
Logon.java
in jrun_root/servers/tutorial/compass-ear/compass-war/
WEB-INF/classes/compass.
In the next step, you enable dynamic servlet and class compiling and reloading.
Содержание 38000382 - Macromedia JRun - Mac
Страница 1: ...Getting Started with JRun...
Страница 16: ......
Страница 68: ...54 Chapter 5 Introduction to EJB...
Страница 82: ......
Страница 110: ...96 Lesson 3 EJB Tutorial...
Страница 128: ...114 Lesson 4 Web Services Tutorial...
Страница 132: ...118 Index...