Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP problem

 
Donna Harrington
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 305
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a million for your help Jeffrey
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic