Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

JSP & HTML ... 2different pages works in 1page ...HELP

gantsgants Member Posts: 10
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

  • gantsgants Member Posts: 10
    PLEASE NOTE: this login does work correctly, so all i need to know is how do i seperate the JSP and the HTML???
    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">
    :

    :  
    : 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
    :

Sign In or Register to comment.