BUG!

I am designing a portal application. There are only 3 pages: #1 Login page that submits a form to #2. a main jsp page that includes #3. Another jsp which defines a class. The application works fine (you can put your login info in and it will search a database and do other stuff) it even givs you a javascript alert when you miss needed info.

The problem is when you put bad info in because it alerts you and brings you back to the login form. That is fine but after that point you cant login with the correct info unless you resave the main jsp page (the one that is submitted to when you login #2).

I am using the javawebserver on an NT machine. I dont know if it is a bug in javaserverpages or in the javawebserver.

If you have any info let me know.

Thanks in advance!

Here is the code for the jsp's.

Main jsp page:

<HTML>

<Head>

<title>EDS Portal</title>

</Head>

<BODY>

<%-- dbconnect.jsp modified 7/30/01 --%>

<%@ include file="dbconnect.jsp" %>

<%-- Coded by: Luke Landwehr, EDS (Electronic Data Systems)--%>

<%-- couldn't use setName(getparam...); or getname--%>

<% UserName =(String) request.getParameter("name"); %>

<% UserPassword =(String) request.getParameter("password"); %>

<Script>

//alert("<%= UserName %>");

//alert("<%= UserPassword %>");

</Script>

<%= getDbconnection() %>

<Center><H1>Welcome to the EDS Portal <%= getFirstName() %> </H1>

<Form method='post' action='<%= getUrl() %>' name='loginfrm'>

<INPUT TYPE=hidden NAME=firstname VALUE="<%= getFirstName() %>">

<INPUT TYPE=hidden NAME=lastname VALUE="<%= getLastName() %>">

<INPUT TYPE=hidden NAME=id VALUE="<%= getUserID() %>">

<INPUT TYPE=hidden NAME=role VALUE="<%= getRoleID() %>">

<input type='submit' name='submit' value='<%= getServiceName() %>'>

</Form>

</Center>

<%= getNextForm() %>

<%

while (url.length() != 0)

{

%>

<Center>

<Form method='post' action='<%= getUrl() %>' name='loginfrm'>

<INPUT TYPE=hidden NAME="TXTPASSWORD" VALUE="<%= getPassword() %>">

<INPUT TYPE=hidden NAME="TXTUSERNAME" VALUE="<%= getName() %>">

<INPUT TYPE=hidden NAME="firstname" VALUE="<%= getFirstName() %>">

<INPUT TYPE=hidden NAME="lastname" VALUE="<%= getLastName() %>">

<INPUT TYPE=hidden NAME="id" VALUE="<%= getUserID() %>">

<INPUT TYPE=hidden NAME="role" VALUE="<%= getRoleID() %>">

<input type='submit' name='submit' value='<%= getServiceName() %>'>

</Form>

</Center>

<%= getNextForm() %>

<%

}

%>

</Body>

</Html>

class jsp

<%-- connects to a db and serves info to the display jsp --%>

<%@ page import="java.io.*" %>

<%@ page import="javax.servlet.ServletException" %>

<%@ page import="javax.servlet.http.*" %>

<%@ page import="javax.servlet.*" %>

<%@ page import="java.util.Enumeration" %>

<%@ page import="java.sql.*" %>

<%@ page import="java.util.*" %>

<%!

private ResultSet userInfo;

private Statement stmt;

private String pw;

private String FirstName;

private String LastName;

private String UserName="";

private String UserPassword="";

private int UserID;

private int RoleID;

private String url;

private String ServiceName="";

private String Message2="";

public void setName(String Name){

UserName = Name;

}

public String getName(){

return UserName;

}

public void setPassword(String Password){

UserPassword = Password;

}

public String getPassword(){

return UserPassword;

}

public String getFirstName(){

return FirstName;

}

public String getLastName(){

return LastName;

}

public String getUrl(){

return url;

}

public int getUserID(){

return UserID;

}

public int getRoleID(){

return RoleID;

}

public String getServiceName(){

return ServiceName;

}

public String getDbconnection() {

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();

DriverManager.setLoginTimeout(60);

Connection con = DriverManager.getConnection("jdbc:odbc:Portal");

stmt = con.createStatement();

String query = "SELECT EMP_TABLE.EMP_PASS, MGR_SERVICES.SERVICE_ID,";

query = query +" MGR_SERVICES.DEFAULT_URL, EMP_TABLE.EMP_USER_ID, *";

query = query +"FROM (EMP_TABLE LEFT JOIN MGR_USER_SERVICES ON";

query = query +" EMP_TABLE.EMP_USER_ID = MGR_USER_SERVICES.USER_ID)";

query = query +" LEFT JOIN MGR_SERVICES ON MGR_USER_SERVICES.SERVICE_ID =";

query = query +" MGR_SERVICES.SERVICE_ID WHERE (((EMP_TABLE.EMP_LAN_ID)='" + UserName+ "'))";

userInfo = stmt.executeQuery(query);

if(userInfo.next())

{

pw = userInfo.getString("EMP_PASS");

if (UserPassword.equals(pw))

{

FirstName = userInfo.getString("EMP_FIRST");

LastName = userInfo.getString("EMP_LAST");

UserID = userInfo.getInt("EMP_USER_ID");

RoleID = userInfo.getInt("ROLE_ID");

url=userInfo.getString("DEFAULT_URL");

ServiceName = userInfo.getString("SERVICE_NAME");

}

else

{

Message2 = "<Script Language=JavaScript>";

Message2 = Message2 + "alert('Your Password Information is incorrect');";

Message2 = Message2 + "window.location.href = 'Login.html'";

Message2 = Message2 + "</Script>";

}

}

else

{

Message2 = "<Script Language=JavaScript>";

Message2 = Message2 + "alert('Your Login Information is incorrect');";

Message2 = Message2 + "window.location.href = 'Login.html'";

Message2 = Message2 + "</Script>";

}

}

catch (InstantiationException i)

{return (i.toString());}

catch (ClassNotFoundException c)

{return (c.toString());}

catch (SQLException sql)

{return (sql.toString());}

catch (Exception e)

{return (e.toString());}

return Message2;

}

public String getNextForm() {

try

{

url="";

ServiceName="";

if(userInfo.next())

{

url=userInfo.getString("DEFAULT_URL");

ServiceName = userInfo.getString("SERVICE_NAME");

RoleID = userInfo.getInt("ROLE_ID");

}

}

catch (SQLException sql)

{return (sql.toString());}

return Message2;

}

%>

[7091 byte] By [skywalker0110] at [2007-9-26 2:32:56]
# 1

> <Center><H1>Welcome to the EDS Portal <%=

&gt; getFirstName() %> </H1>

> <Form method='post' action='<%= getUrl() %>'

> name='loginfrm'>

My guess is that the action (url) is not set correctly in the case of an error. Add a line which prints out the url to the page so you can observe it's value.

//.........

public String getDbconnection() {

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();

//.........

You shouldn't actually instantiate the driver - you are only required to load it's class.

smiths at 2007-6-29 9:55:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

What do you mean by resave the page? Do you mean resubmit?.

> is fine but after that point you cant login with the

> correct info unless you resave the main jsp page (the

> one that is submitted to when you login #2).

This is pretty bad, your going to have to change the way your doing this. When your including the dbConnect.jsp you are actually declearing many instance variables for the jsp. These are going to end up being global vars that are used by everyone. So one request comes in sets the vars but another may come in right behind it and set those vars before the first request is even done. Not very good.

> <%-- dbconnect.jsp modified 7/30/01 --%>

> <%@ include file="dbconnect.jsp" %>

>

All of these end up being global variables used by every request not just a single request. This is information that should be placed into a bean and not into a jsp page. Jsp's are not intended for this kind of use. i.e trying to use it as a helper class. My guess is that any kind of problem you are having is centered around this.

> private ResultSet userInfo;

> private Statement stmt;

> private String pw;

> private String FirstName;

> private String LastName;

> private String UserName="";

> private String UserPassword="";

> private int UserID;

> private int RoleID;

> private String url;

> private String ServiceName="";

> private String Message2="";

bobd3 at 2007-6-29 9:55:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...