vb6vb6
asked on
problem with my code?
index.jsp
========================== ========== =========
<%
session.putValue("USER_INT _KEY", "INVALID");
session.putValue("option_c hosen", "gen_rev");
%>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<FRAMESET ROWS="13%, *" >
<FRAME SRC="top.html" name="top" noresize scrolling="no" target="main">
<FRAMESET COLS="16%, *">
<FRAME SRC="main_menu.html" name="left" noresize scrolling="auto" target="main">
<FRAME SRC="main_information.html " name="main">
</FRAMESET>
<NOFRAMES><BODY></BODY></N OFRAMES>
</FRAMESET>
</HTML>
main_menu.html
========================== ========== ========== ===
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<A HREF="login.jsp" target="main">Login</A><BR >
<A HREF="gen_rev.html" target="main">Review Items</A><BR>
</BODY>
</HTML>
login.jsp
========================== ========== ========== ==
<%@ page errorPage="error.jsp" import="java.util.*,java.s ql.*"%>
<%
String strOptionChosen = null;
String strLoginID = "";
String strPassword = "";
String strMessage = "";
String strUSER_INT_KEY = null;
strOptionChosen = session.getValue("option_c hosen").to String();
if (session.getValue("USER_IN T_KEY") == null)
{
session.putValue("USER_INT _KEY", "INVALID");
}
strUSER_INT_KEY = session.getValue("USER_INT _KEY").toS tring();
if (!(session.getValue("USER_ INT_KEY"). toString() .equals("I NVALID")))
{
if (session.getValue("option_ chosen") != null)
response.sendRedirect(strO ptionChose n + ".jsp");
else
response.sendRedirect("gen _rev.jsp") ;
}
if (session.getValue("USER_IN T_KEY").to String().e quals("INV ALID"))
{
if (request.getParameter("LOG IN_ID") != null)
{
strLoginID = request.getParameter("LOGI N_ID");
strPassword = request.getParameter("PASS WORD");
String strSQLQuery = null;
Connection conOracle = null;
try
{
Class.forName("sun.jdbc.od bc.JbdcOdb cDriver");
conOracle = DriverManager.getConnectio n("jdbc:od bc:store", "Scott", "Tiger");
strSQLQuery = "Select USER_INT_KEY, LOGON_ID, PASSWORD ";
strSQLQuery += "from T_ACT_USER ";
strSQLQuery += "where lower(LOGON_ID) = lower('" + strLoginID.trim() + "')";
strSQLQuery += "and lower(PASSWORD) = lower('" + strPassword.trim() + "')";
Statement stmtSQL = null;
ResultSet rsSource = null;
stmtSQL = conOracle.createStatement( );
rsSource = stmtSQL.executeQuery(strSQ LQuery);
while (rsSource.next())
{
strUSER_INT_KEY = rsSource.getString("USER_I NT_KEY");
}
if (strUSER_INT_KEY != null)
{
session.putValue("USER_INT _KEY", strUSER_INT_KEY);
String Is_SQLCustVisitCount = null;
Is_SQLCustVisitCount = "update T_ACT_USER ";
Is_SQLCustVisitCount += "set visit_count = visit_count + 1 ";
Is_SQLCustVisitCount += "where USER_INT_KEY = " + strUSER_INT_KEY;
PreparedStatement pstmtUpdate = null;
pstmtUpdate = conOracle.prepareStatement (Is_SQLCus tVisitCoun t);
pstmtUpdate.executeUpdate( );
if (session.getValue("option_ chosen") != null)
response.sendRedirect(strO ptionChose n + ".jsp");
else
response.sendRedirect("gen _rev.jsp") ;
}
else
{
strMessage = "User ID and Password not found";
}
}
catch(ClassNotFoundExcepti on e)
{
strMessage += "ClassNotFoundException when connecting to Database";
}
catch(SQLException e)
{
strMessage += "SQLException when connecting to Database" + e.getMessage();
}
}
}
%>
<HTML>
<HEAD>
<TITLE>Login ID TEST</TITLE>
</HEAD>
<BODY>
<%
if (strMessage != "")
{
out.println("<P><FONT FACE=ARIAL SIZE=3 COLOR=RED>Error: " + strMessage);
}
%>
<FORM ACTION="login.jsp" TARGET="main" METHOD="POST" >
<TABLE BORDER="0">
<TR><TD>Login ID: </TD>
<TD><INPUT TYPE="TEXT" NAME="LOGON_ID" SIZE="18" VALUE=<%=strLoginID%>></TD ></TR>
<TR><TD>Password: </TD>
<TD><INPUT TYPE="PASSWORD" NAME="PASSWORD" SIZE="18" VALUE=<%=strPassword%>></T D></TR>
<TR><TD><INPUT TYPE="SUBMIT" VALUE="Submit"></TD>
<TD><INPUT TYPE="RESET" VALUE="Reset"></TD></TR>
</TABLE>
</FORM>
</BODY>
</HTML>
I established an ODBC Connection - Microsoft ODBC for Oracle. I created the table in SQL *PLUS and added the data to this table. I opened the index.jsp file using http://localhost:8100/index.jsp in the IE browser and clicked on login.jsp on the left navigation. When I entered the login id and password and clicked on submit button. It's nothing. Something wrong with my code?? Please advice.
==========================
<%
session.putValue("USER_INT
session.putValue("option_c
%>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<FRAMESET ROWS="13%, *" >
<FRAME SRC="top.html" name="top" noresize scrolling="no" target="main">
<FRAMESET COLS="16%, *">
<FRAME SRC="main_menu.html" name="left" noresize scrolling="auto" target="main">
<FRAME SRC="main_information.html
</FRAMESET>
<NOFRAMES><BODY></BODY></N
</FRAMESET>
</HTML>
main_menu.html
==========================
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<A HREF="login.jsp" target="main">Login</A><BR
<A HREF="gen_rev.html" target="main">Review Items</A><BR>
</BODY>
</HTML>
login.jsp
==========================
<%@ page errorPage="error.jsp" import="java.util.*,java.s
<%
String strOptionChosen = null;
String strLoginID = "";
String strPassword = "";
String strMessage = "";
String strUSER_INT_KEY = null;
strOptionChosen = session.getValue("option_c
if (session.getValue("USER_IN
{
session.putValue("USER_INT
}
strUSER_INT_KEY = session.getValue("USER_INT
if (!(session.getValue("USER_
{
if (session.getValue("option_
response.sendRedirect(strO
else
response.sendRedirect("gen
}
if (session.getValue("USER_IN
{
if (request.getParameter("LOG
{
strLoginID = request.getParameter("LOGI
strPassword = request.getParameter("PASS
String strSQLQuery = null;
Connection conOracle = null;
try
{
Class.forName("sun.jdbc.od
conOracle = DriverManager.getConnectio
strSQLQuery = "Select USER_INT_KEY, LOGON_ID, PASSWORD ";
strSQLQuery += "from T_ACT_USER ";
strSQLQuery += "where lower(LOGON_ID) = lower('" + strLoginID.trim() + "')";
strSQLQuery += "and lower(PASSWORD) = lower('" + strPassword.trim() + "')";
Statement stmtSQL = null;
ResultSet rsSource = null;
stmtSQL = conOracle.createStatement(
rsSource = stmtSQL.executeQuery(strSQ
while (rsSource.next())
{
strUSER_INT_KEY = rsSource.getString("USER_I
}
if (strUSER_INT_KEY != null)
{
session.putValue("USER_INT
String Is_SQLCustVisitCount = null;
Is_SQLCustVisitCount = "update T_ACT_USER ";
Is_SQLCustVisitCount += "set visit_count = visit_count + 1 ";
Is_SQLCustVisitCount += "where USER_INT_KEY = " + strUSER_INT_KEY;
PreparedStatement pstmtUpdate = null;
pstmtUpdate = conOracle.prepareStatement
pstmtUpdate.executeUpdate(
if (session.getValue("option_
response.sendRedirect(strO
else
response.sendRedirect("gen
}
else
{
strMessage = "User ID and Password not found";
}
}
catch(ClassNotFoundExcepti
{
strMessage += "ClassNotFoundException when connecting to Database";
}
catch(SQLException e)
{
strMessage += "SQLException when connecting to Database" + e.getMessage();
}
}
}
%>
<HTML>
<HEAD>
<TITLE>Login ID TEST</TITLE>
</HEAD>
<BODY>
<%
if (strMessage != "")
{
out.println("<P><FONT FACE=ARIAL SIZE=3 COLOR=RED>Error: " + strMessage);
}
%>
<FORM ACTION="login.jsp" TARGET="main" METHOD="POST" >
<TABLE BORDER="0">
<TR><TD>Login ID: </TD>
<TD><INPUT TYPE="TEXT" NAME="LOGON_ID" SIZE="18" VALUE=<%=strLoginID%>></TD
<TR><TD>Password: </TD>
<TD><INPUT TYPE="PASSWORD" NAME="PASSWORD" SIZE="18" VALUE=<%=strPassword%>></T
<TR><TD><INPUT TYPE="SUBMIT" VALUE="Submit"></TD>
<TD><INPUT TYPE="RESET" VALUE="Reset"></TD></TR>
</TABLE>
</FORM>
</BODY>
</HTML>
I established an ODBC Connection - Microsoft ODBC for Oracle. I created the table in SQL *PLUS and added the data to this table. I opened the index.jsp file using http://localhost:8100/index.jsp in the IE browser and clicked on login.jsp on the left navigation. When I entered the login id and password and clicked on submit button. It's nothing. Something wrong with my code?? Please advice.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I changed LOGIN_ID to LOGON_ID. I got an error : Error:ClassNotFoundExcepti on when connecting to Database. I think this means that it does not connect to Database.
I established an ODBC connection Microsoft ODBC for Oracle and created the T_ACT_USER table in SQL *PLUS and inserted the values to this table.
I tested the test code:
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%
try
{
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
String url="jdbc:odbc:store";
Connection con=DriverManager.getConne ction(url, "Scott", "Tiger");
Statement stmt = con.createStatement();
String query="CREATE TABLE COFFEES" +
"(COF_NAME VARCHAR(32),"+
"SUP_ID NUMBER,"+
"PRICE NUMBER,"+
"SALES NUMBER,"+
"TOTAL NUMBER)";
stmt.executeUpdate(query);
}
catch (Exception e) {}
out.println("table coffees created");
%>
I got no error and checked the Coffees table in SQL *PLUS. But I don't understand why I am getting an error for my login page. Please advice.
I established an ODBC connection Microsoft ODBC for Oracle and created the T_ACT_USER table in SQL *PLUS and inserted the values to this table.
I tested the test code:
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%
try
{
Class.forName("sun.jdbc.od
String url="jdbc:odbc:store";
Connection con=DriverManager.getConne
Statement stmt = con.createStatement();
String query="CREATE TABLE COFFEES" +
"(COF_NAME VARCHAR(32),"+
"SUP_ID NUMBER,"+
"PRICE NUMBER,"+
"SALES NUMBER,"+
"TOTAL NUMBER)";
stmt.executeUpdate(query);
}
catch (Exception e) {}
out.println("table coffees created");
%>
I got no error and checked the Coffees table in SQL *PLUS. But I don't understand why I am getting an error for my login page. Please advice.
ASKER
Never Mind. Sorry.
>I got an error : Error:ClassNotFoundExcepti on when connecting to Database.
I think the package sun.jdbc.odbc.JbdcOdbcDriv e doesn't in your classpath. Please check your classpath.
I think the package sun.jdbc.odbc.JbdcOdbcDriv
ASKER
I solved the ClassNotFoundException but I got another error!
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-00942: table or view does not exist
What does that mean?
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-00942: table or view does not exist
What does that mean?
ASKER
Never mind! Again!
ASKER
I solved it by fixing the ORA-00942 error.
Seem like it is sql syntax problem.
Check this,
strSQLQuery = "Select USER_INT_KEY, LOGON_ID, PASSWORD ";
strSQLQuery += "from T_ACT_USER ";
strSQLQuery += "where lower(LOGON_ID) = lower('" + strLoginID.trim() + "')";
strSQLQuery += "and lower(PASSWORD) = lower('" + strPassword.trim() + "')";
For the third statement, it should be ending with a space.
Check this,
strSQLQuery = "Select USER_INT_KEY, LOGON_ID, PASSWORD ";
strSQLQuery += "from T_ACT_USER ";
strSQLQuery += "where lower(LOGON_ID) = lower('" + strLoginID.trim() + "')";
strSQLQuery += "and lower(PASSWORD) = lower('" + strPassword.trim() + "')";
For the third statement, it should be ending with a space.
Check whether u establish connection with the database.
Print the connection and see in ur browser.
If connection is null then problem is with backend or with the connection URL.(connection bean)
(please dont send code tell the problem we will analyse and try to give soln to U)
Good Luck
Vasan S