Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with JSP, session, login, JDBC.

843836Jan 17 2004 — edited Jan 24 2004
This is the template login.jsp file I have at the moment.
<%@ page errorPage="errorPage.jsp" %>
<% 
  String login = (String)request.getParameter("loginname");

  if (login == null || login.equals("")) {
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
<HEAD>
<TITLE>Login Page</TITLE>
<STYLE>
<!--
font.loginhead {
  font-family: Arial,Helvetica,sans-serif;
  font-size:12pt; font-weight: 600; color: #000000;
}
font.loginform {
  font-family: Arial,Helvetica,sans-serif;
  font-size:10pt; font-weight: 600; color: #ffffff;
}
-->
</STYLE>
</HEAD>

<BODY>
<jsp:include page="debug.jsp" flush="true" />

<CENTER>
<FONT CLASS="loginhead">
LOGIN REQUIRED:
</FONT>
<BR>

<FORM NAME="loginform" METHOD=post>
<TABLE BGCOLOR=#990022 BORDER=0 CELLPADDING=5 CELLSPACING=0>

<TR><TD ALIGN=right>
<FONT CLASS="loginform">
Login Name:
</FONT>
</TD><TD ALIGN=left>
<FONT CLASS="loginform">
<INPUT TYPE=text NAME="loginname" SIZE=10>
</FONT>
</TD></TR>

<TR><TD ALIGN=right>
<FONT CLASS="loginform">
Password:
</FONT>
</TD><TD ALIGN=left>
<FONT CLASS="loginform">
<INPUT TYPE=password NAME="loginpassword" SIZE=10>
</FONT>
</TD></TR>

<TR><TD COLSPAN=2 ALIGN=center>
<FONT CLASS="loginform">
<INPUT TYPE=SUBMIT VALUE="Login">
</FONT>
</TD></TR>
</TABLE>

</FORM>
</CENTER>

</BODY>
</HTML>
<% 
  } else {
 /*
   Checking against database that username and password are correct.
 */
    session.putValue("login", login);
    session.setMaxInactiveInterval(600);

    String loginpoint 
       = (String)session.getValue("loginpoint"); 
    if (loginpoint == null) {
      StringBuffer defaultpoint = new StringBuffer();
      defaultpoint.append(request.getScheme())
                  .append("://")
                  .append(request.getServerName())
                  .append("/"); 

      loginpoint = defaultpoint.toString();
    } else {
      session.removeValue("loginpoint");
    }

    response.sendRedirect(loginpoint);  
  }
I know as much as how connect to the database, create a statement and check to see if the username and password are correct, I dont know how to actually take what the user has typed in and put it in an mysql query. I have an idea that maybe I can convert Login and Loginpassword to Strings but I don't know how to do this.

This is how I plan to connect to the database above
//here I need to have login and loginpasword in separate Strings so I can use them in a query.
Connection connection;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://localhost/Users");
Statement statement=connection.createStatement();
String qry="select PassWord from customers where UserName='"+stringLogin+"'";
ResultSet rs= statement.executeQuery(qry);
In my login.jsp file above I don't understand the following code, and why it is needed. Can someone explain please.
session.putValue("login", login);
    session.setMaxInactiveInterval(600);

    String loginpoint 
       = (String)session.getValue("loginpoint"); 
    if (loginpoint == null) {
      StringBuffer defaultpoint = new StringBuffer();
      defaultpoint.append(request.getScheme())
                  .append("://")
                  .append(request.getServerName())
                  .append("/"); 

      loginpoint = defaultpoint.toString();
    } else {
      session.removeValue("loginpoint");
    }

    response.sendRedirect(loginpoint);  
  }
Hope you can understand what I'm trying to explain what my problems are.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2004
Added on Jan 17 2004
1 comment
136 views