aspose file tools*
The moose likes JSP and the fly likes JSP problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP problem" Watch "JSP problem" New topic
Author

JSP problem

Donna Harrington
Ranch Hand

Joined: Aug 08, 2003
Posts: 31
hey,
hope somebody can help me with this, i cannot see what i'm doing wrong.
I have a html page where a user enters username and password, it is then checked at database and see's whether a user is administrator or user.If a user, user is taken to productpet shop. If its an administrator its taken to administrator screen.It is outputting the username and password but doesnt do anything else. I have all the jsp pages created. here is my connection code etc:
Thanx
<% Connection c = null;
Statement s = null;
ResultSet rs = null;
String driver="com.mysql.jdbc.Driver";
String connectionURL="jdbc:mysql://localhost:8084/petshopwebsite";
String pw = "";
String acc = "";



%>
<html>
<head><title>Signin2</title></head>
<body>
<BODY BGCOLOR="#228B22">
<%

String Username = request.getParameter("Username");
String Password = request.getParameter("Password");
System.out.println(Username);
System.out.println(Password);
String accessLevel = "";
String password = "";
String username ="root";
String access = "";
System.out.println(Username);
System.out.println(Password);
System.out.println(accessLevel);


try {
Class.forName("com.mysql.jdbc.Driver");
}

catch(ClassNotFoundException xyz) {}

try{
c = DriverManager.getConnection(connectionURL,username, password);
PreparedStatement p = c.prepareStatement("SELECT * from customerdetails where Username ='" + Username+"'");
rs = p.executeQuery();


while(rs.next())
{
pw = rs.getString("Password");
System.out.println(pw);


acc = rs.getString ("access");
out.println(acc);
}
if(rs == null)
{
System.out.println("Wrong information was entered");

%>
<jsp:include page = "error.jsp"/> <%--display this page on the current page--%>
<%
}
}
catch(SQLException tr){
tr.printStackTrace();
}

System.out.println(pw + "really is" + Password);
if(Password.equals(pw))
{
if(acc.equals("Administrator"))
{
System.out.println("Access Level OK");
%>


<jsp:include page = "Admin.jsp"/> <%--display this page on the current page--%>
<%
}
if(acc.equals("User"))
{
System.out.println("Access Level OK");
%>

<jsp:include page = "ProductPetShop.jsp"/><%--display this page on the current page--%>
<%
}
}
else{
System.out.println("blah");
%>
<jsp:include page = "error.jsp"/>
<%
}

%>
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
This looks kind of wierd, what you're doing with the page includes. Once you authenticate the user, you can use the following:

This will direct the user to newPage. Before this call, you can check the type of user (admin, etc.) and direct them appropriately. Look at some of the other threads around the JSP forum to get an idea of how you should set your pages up -- (less Java code in the JSP the better). Ideally, you'd want a Servlet to handle all the authentication, and the Servlet would ultimately be responsible for directing the user to the correct page.
Donna Harrington
Ranch Hand

Joined: Aug 08, 2003
Posts: 31
Thanx a million for your help Jeffrey
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP problem
 
Similar Threads
Help with this code!
SQL error
JSP Bean Problem
SQL syntax error
Comparing value of radio button against answer from the database