• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP problem

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"/>
<%
}

%>
 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a million for your help Jeffrey
 
reply
    Bookmark Topic Watch Topic
  • New Topic