Hows it goin?
i have created a simple login page with HTML and JSP all in the one page but want to keep all my JSP pages seperate to the HTML. But when i seperate the two files it doesn't work. Here is the code to explain:
Loginpage
<%@ page import="java.sql.*" %>
<% String connectionURL = "jdbc:mysql://localhost/users";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
%>
<%if (request.getMethod().equalsIgnoreCase("POST")){
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL);
statement = connection.createStatement();
String username = request.getParameter("textfield");
String password = request.getParameter("textfield2");
String Query = "SELECT password FROM users WHERE username = '" + username + "'";
rs = statement.executeQuery(Query);
if(rs.next() && rs.getString("password").equals(password))
{
response.sendRedirect("site_map.jsp");
session.setAttribute( "theName", username );
}
else{
response.sendRedirect("loginerror.jsp");
session.setAttribute( "theName", username );
session.setAttribute( "thePassword", password );
}
rs.close();
}
%>
|
|
|
|
|
|
/login4.jsp" METHOD="post">
Login
Username
Password
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
SORRY ABOUT THE AMOUNT CODE.
WOULD REALLY APPRICATE ANY HELP.
THANKS,
GANTS
Comments
thanks
: Hows it goin?
: i have created a simple login page with HTML and JSP all in the one page but want to keep all my JSP pages seperate to the HTML. But when i seperate the two files it doesn't work. Here is the code to explain:
:
:
:
: Loginpage
:
:
:
: <%@ page import="java.sql.*" %>
:
: <% String connectionURL = "jdbc:mysql://localhost/users";
: Connection connection = null;
: Statement statement = null;
: ResultSet rs = null;
: %>
:
: %>
: <%if (request.getMethod().equalsIgnoreCase("POST")){
: Class.forName("org.gjt.mm.mysql.Driver").newInstance();
: connection = DriverManager.getConnection(connectionURL);
: statement = connection.createStatement();
: String username = request.getParameter("textfield");
: String password = request.getParameter("textfield2");
: String Query = "SELECT password FROM users WHERE username = '" + username + "'";
: rs = statement.executeQuery(Query);
:
:
: if(rs.next() && rs.getString("password").equals(password))
: {
: response.sendRedirect("site_map.jsp");
: session.setAttribute( "theName", username );
: }
: else{
: response.sendRedirect("loginerror.jsp");
: session.setAttribute( "theName", username );
: session.setAttribute( "thePassword", password );
: }
:
: rs.close();
: }
: %>
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
: /login4.jsp" METHOD="post">
: :
Username
::
:
Password
::
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
: SORRY ABOUT THE AMOUNT CODE.
: WOULD REALLY APPRICATE ANY HELP.
: THANKS,
: GANTS
: