Hello there!
I am doing a project using the purchased java connector.
I have the connected user username in a session variable, (“username”), and I need to log this to the logfile whenever I do updates using a form connector.
I noticed that using php I can add custom log entries using
LogMaster::log(“any text here”);
but my question is
how do I write custom log entries in JAVA ?
how do I get the session variable from the java connector script ?
At present my script is simply:
public class CnctEleCLGForm extends ConnectorServlet { @Override
protected void configure() {
Connection conn = ( new DataBaseConnection()).getConnection();
FormConnector c = new FormConnector(conn, DBType.Oracle);
c.enable_log(“/logs/cnctEleCLGForm.log”, true);
c.event.attach(new eleDataCustomBehavior());
c.render_table(“CLG_ELEZIONI”,“CLG_ELE_ID”,“MOT_ELE_MOT_ELE_ID,TIPOGIUNTA_TIPOGIUNTA_ID,ELETTORI,ELETTORI_MASCHI,ELETTORI_FEMMINE,SEZIONI,VOTANTI,VOTANTI_MASCHI,VOTANTI_FEMMINE,NON_VALIDI,NULLE,BIANCHE,ASTENUTI,SCHEDE_NULLE_CAND,VALIDI_ALLE_LISTE,VALIDI_AI_CANDIDATI,VALIDI_SOLO_AI_CANDIDATI,NOTE”);
}
To get variable from session you should get object HttpSession. To do it you should use ThreadSafeConnectorServlet instead of ConnectorServlet:
public class CnctEleCLGForm extends ConnectorServlet {
@Override
protected void configure(HttpServletRequest req, HttpServletResponse res) {
Connection conn = ( new DataBaseConnection()).getConnection();
FormConnector c = new FormConnector(conn, DBType.Oracle);
c.enable_log("/logs/cnctEleCLGForm.log", true);
c.servlet(req, res);
String value = req.getSession(true).getValue();
// now you may pass value or session object into behavior constructor
c.event.attach(new eleDataCustomBehavior());
c.render_table("CLG_ELEZIONI","CLG_ELE_ID","MOT_ELE_MOT_ELE_ID,TIPOGIUNTA_TIPOGIUNTA_ID,ELETTORI,ELETTORI_MASCHI,ELETTORI_FEMMINE,SEZIONI,VOTANTI,VOTANTI_MASCHI,VOTANTI_FEMMINE,NON_VALIDI,NULLE,BIANCHE,ASTENUTI,SCHEDE_NULLE_CAND,VALIDI_ALLE_LISTE,VALIDI_AI_CANDIDATI,VALIDI_SOLO_AI_CANDIDATI,NOTE");
}
}
One more question: what java versions are your libraries compatible with? I ask because my customer is using Tomcat 5.5 which only supports J2EE 1.2, 1.3, and 1.4 Web modules