1/sql file:
package com.allClass.SQL;
import com.allClass.Database.DatabaseConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PersonalInfo {
private Connection con = null;
private Statement st = null;
private ResultSet rs = null;
private DatabaseConnection dbc = new DatabaseConnection();
public String getCurrentLoginInfo() {
boolean flag = true;
String loginInfoString = "";
String query = "";
this.con = this.dbc.connectDB();
if (this.con == null) {
flag = false;
loginInfoString = null;
}
if (flag) {
try {
this.st = this.con.createStatement();
/*query = "SELECT PKG_DRPATCAREQUERY.FNC_TODATE(SYSDATE) logInDateTime FROM DUAL";*/
query = "SELECT FNC_TODATE(SYSDATE) logInDateTime FROM DUAL";
this.rs = this.st.executeQuery(query);
while (this.rs.next()) {
loginInfoString = this.rs.getString("logInDateTime").trim();
}
} catch (SQLException sq) {
loginInfoString = null;
sq.printStackTrace();
try {
this.rs.close();
this.st.close();
this.con.close();
} catch (SQLException ex) {
loginInfoString = null;
ex.printStackTrace();
}
} finally {
try {
this.rs.close();
this.st.close();
this.con.close();
} catch (SQLException ex) {
loginInfoString = null;
ex.printStackTrace();
}
}
}
return loginInfoString;
}
}
2/javaaction file:
package com.allClass.Action;
import com.allClass.Database.DatabaseConnection;
import com.allClass.SQL.PersonalInfo;
import com.allClass.Session.SessionVariable;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;// This is use for add field error
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;// For date
import util.DateFormating;//For date
public class LogInPageAction extends ActionSupport{
// use for log in username and passward kaniz
private String userName;
private String password;
private String datVal;
//
private Connection con = null;
private Statement st = null;
private CallableStatement cs = null;
private ResultSet rs = null;
private DatabaseConnection dbc = new DatabaseConnection();
String query = "";
public String logInPage() {
return "logInPage";
}
//START Login code **************
public String userSignIns(){
SessionVariable sessionVariable = new SessionVariable();//For session get time
int usrname = 0;
//String usrname = "";
System.out.println("hhhh");
boolean fg = true;
con = dbc.connectDB();
ActionContext.getContext().getSession().put(sessionVariable.getDbConnectionSession(), con); //For session get time
if (con == null) {
fg = false;
}
if (fg) {
try {
st = con.createStatement();
//rs.getString for:// query = "select USER_ID from login_users where USER_ID='" + userName + "' and PASSWORD='" + password + "'";
query = "select * from login_users where LOGIN_NAME='" + userName + "' and PASSWORD='" + password + "'";
System.out.println(query);
rs = st.executeQuery(query);
while (rs.next()) {
usrname = rs.getRow();
//usrname = rs.getString("USER_ID"); or usrname = rs.getString("LOGIN_NAME");
}
} catch (SQLException sq) {
sq.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
// if (!usrname.isEmpty()) {
if (usrname>0) {
//************************ Start My necessary call function ************************
PersonalInfo personalInfo = new PersonalInfo();//For session get time
String personLogInTime = personalInfo.getCurrentLoginInfo();//For session get time
ActionContext.getContext().getSession().put("logInTime",personLogInTime);//For session get time
//ActionContext.getContext().getSession().put("logInInfoDate",new Date());
//************************ End My necessary call function ************************
return "userSignIns";
}else{
//addFieldError("logMsg","Your Account Is Not active!!"); //N.B: After add field error message
return "logInFail";
}
//return "enterLogInPageFail";
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//END Log in code ***************
public String getDatVal() {
return datVal;
}
public void setDatVal(String datVal) {
this.datVal = datVal;
}
}
session variable dot java:
package com.allClass.Session;
public class SessionVariable {
private final String dbConnectionSession = "dbConnectionSession";
private final String levelNo = "levelNo";
private final String patientType = "patientType";
private final String userLogInInfo = "logInInfo";
private final String empName = "empName";
private final String imageSqlInfo = "imageSqlInfo";
private final String patImageSqlInfo = "patImageSqlInfo";
private final String displayPatientXml = "displayPatientXml";
public String getUserLogInInfo() {
return "logInInfo";
}
public String getDbConnectionSession() {
return "dbConnectionSession";
}
public String getPatientType() {
return "patientType";
}
public String getLevelNo() {
return "levelNo";
}
public String getImageSqlInfo() {
return "imageSqlInfo";
}
public String getPatImageSqlInfo() {
return "patImageSqlInfo";
}
public String getDisplayPatientXml() {
return "displayPatientXml";
}
public String getEmpName() {
return "empName";
}
}
jsp page:
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page language="java" import="com.opensymphony.xwork2.ActionContext" %>
<%@ page import="com.allClass.Session.SessionVariable"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
SessionVariable sessionVariable=new SessionVariable();
String empName =(String)ActionContext.getContext().getSession().get("empName");
String loginTime =(String)ActionContext.getContext().getSession().get("logInTime");
String relPath = "";
relPath = request.getContextPath();
//System.out.println("Relative Path :"+relPath);
if (relPath.length() > 0) {
relPath = relPath + "/DoctorImage.img?clmName=PHOTOGRAPH";
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="da-wrapper" style="float:left;width:100%;height:30px;" class="homePagSloganDiv"><table>
<tr><th>Name : <%=empName %></th><th>Logged on at : <%=loginTime %></th></tr>
</table></div>
<div>sdhfsh</div>
</body>
</html>
package com.allClass.SQL;
import com.allClass.Database.DatabaseConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PersonalInfo {
private Connection con = null;
private Statement st = null;
private ResultSet rs = null;
private DatabaseConnection dbc = new DatabaseConnection();
public String getCurrentLoginInfo() {
boolean flag = true;
String loginInfoString = "";
String query = "";
this.con = this.dbc.connectDB();
if (this.con == null) {
flag = false;
loginInfoString = null;
}
if (flag) {
try {
this.st = this.con.createStatement();
/*query = "SELECT PKG_DRPATCAREQUERY.FNC_TODATE(SYSDATE) logInDateTime FROM DUAL";*/
query = "SELECT FNC_TODATE(SYSDATE) logInDateTime FROM DUAL";
this.rs = this.st.executeQuery(query);
while (this.rs.next()) {
loginInfoString = this.rs.getString("logInDateTime").trim();
}
} catch (SQLException sq) {
loginInfoString = null;
sq.printStackTrace();
try {
this.rs.close();
this.st.close();
this.con.close();
} catch (SQLException ex) {
loginInfoString = null;
ex.printStackTrace();
}
} finally {
try {
this.rs.close();
this.st.close();
this.con.close();
} catch (SQLException ex) {
loginInfoString = null;
ex.printStackTrace();
}
}
}
return loginInfoString;
}
}
2/javaaction file:
package com.allClass.Action;
import com.allClass.Database.DatabaseConnection;
import com.allClass.SQL.PersonalInfo;
import com.allClass.Session.SessionVariable;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;// This is use for add field error
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;// For date
import util.DateFormating;//For date
public class LogInPageAction extends ActionSupport{
// use for log in username and passward kaniz
private String userName;
private String password;
private String datVal;
//
private Connection con = null;
private Statement st = null;
private CallableStatement cs = null;
private ResultSet rs = null;
private DatabaseConnection dbc = new DatabaseConnection();
String query = "";
public String logInPage() {
return "logInPage";
}
//START Login code **************
public String userSignIns(){
SessionVariable sessionVariable = new SessionVariable();//For session get time
int usrname = 0;
//String usrname = "";
System.out.println("hhhh");
boolean fg = true;
con = dbc.connectDB();
ActionContext.getContext().getSession().put(sessionVariable.getDbConnectionSession(), con); //For session get time
if (con == null) {
fg = false;
}
if (fg) {
try {
st = con.createStatement();
//rs.getString for:// query = "select USER_ID from login_users where USER_ID='" + userName + "' and PASSWORD='" + password + "'";
query = "select * from login_users where LOGIN_NAME='" + userName + "' and PASSWORD='" + password + "'";
System.out.println(query);
rs = st.executeQuery(query);
while (rs.next()) {
usrname = rs.getRow();
//usrname = rs.getString("USER_ID"); or usrname = rs.getString("LOGIN_NAME");
}
} catch (SQLException sq) {
sq.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
// if (!usrname.isEmpty()) {
if (usrname>0) {
//************************ Start My necessary call function ************************
PersonalInfo personalInfo = new PersonalInfo();//For session get time
String personLogInTime = personalInfo.getCurrentLoginInfo();//For session get time
ActionContext.getContext().getSession().put("logInTime",personLogInTime);//For session get time
//ActionContext.getContext().getSession().put("logInInfoDate",new Date());
//************************ End My necessary call function ************************
return "userSignIns";
}else{
//addFieldError("logMsg","Your Account Is Not active!!"); //N.B: After add field error message
return "logInFail";
}
//return "enterLogInPageFail";
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//END Log in code ***************
public String getDatVal() {
return datVal;
}
public void setDatVal(String datVal) {
this.datVal = datVal;
}
}
session variable dot java:
package com.allClass.Session;
public class SessionVariable {
private final String dbConnectionSession = "dbConnectionSession";
private final String levelNo = "levelNo";
private final String patientType = "patientType";
private final String userLogInInfo = "logInInfo";
private final String empName = "empName";
private final String imageSqlInfo = "imageSqlInfo";
private final String patImageSqlInfo = "patImageSqlInfo";
private final String displayPatientXml = "displayPatientXml";
public String getUserLogInInfo() {
return "logInInfo";
}
public String getDbConnectionSession() {
return "dbConnectionSession";
}
public String getPatientType() {
return "patientType";
}
public String getLevelNo() {
return "levelNo";
}
public String getImageSqlInfo() {
return "imageSqlInfo";
}
public String getPatImageSqlInfo() {
return "patImageSqlInfo";
}
public String getDisplayPatientXml() {
return "displayPatientXml";
}
public String getEmpName() {
return "empName";
}
}
jsp page:
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page language="java" import="com.opensymphony.xwork2.ActionContext" %>
<%@ page import="com.allClass.Session.SessionVariable"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
SessionVariable sessionVariable=new SessionVariable();
String empName =(String)ActionContext.getContext().getSession().get("empName");
String loginTime =(String)ActionContext.getContext().getSession().get("logInTime");
String relPath = "";
relPath = request.getContextPath();
//System.out.println("Relative Path :"+relPath);
if (relPath.length() > 0) {
relPath = relPath + "/DoctorImage.img?clmName=PHOTOGRAPH";
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div id="da-wrapper" style="float:left;width:100%;height:30px;" class="homePagSloganDiv"><table>
<tr><th>Name : <%=empName %></th><th>Logged on at : <%=loginTime %></th></tr>
</table></div>
<div>sdhfsh</div>
</body>
</html>
No comments:
Post a Comment