• Post Reply Bookmark Topic Watch Topic
  • New Topic

Login Error  RSS feed

 
Kox Williams
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
     I am new to JSP. I tried to develop an application in JSP taking help of some examples from the net.I am using netbeans 7.4,mysql 5.6.19 and tomcat 7.0.41.0.But i get stuck to the very first part.The login part of the application.When I try to log on from index.jsp, the welcome.jsp should load. But instead of that the google page is loading.I have 4 java files under my package Admin.java, DatabaseConnector.java, LoginWorker.java and Result.java.
I have the jsp files namely index.jsp,login.jsp and welcome.jsp. The codes of these jsp files are

index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP</title>
    </head>
    <body bgcolor="cyan">
        <form method =post action="login.jsp">
    <center>
        <h1>*****Student Information System*****</h1>
        </center>
    <br>
    <br>
    <h3>Login here</h3>
    Username :<input type="text" name="user"><br><br>
    Password :<input type="password" name="password"><br><br>
    <input type="submit" value="Login">   <input type="submit" value="Reset">
    </form>   
    </body>
</html>

login.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="com.mypackage.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            Admin a = new Admin();
            a.username = request.getParameter("user");
            a.password = request.getParameter("password");
            String result =LoginWorker.checkLogin(a);
            
            if(result.equals(Result.SUCCESS))
            {
                response.sendRedirect("welcome.jsp");
            }
            else if(result.equals(Result.ACCESS_DENIED))
            {
                response.sendRedirect("index.jsp");
            }
            else
            {
                response.sendRedirect("https://www.google.co.in");
            }
            %>
    </body>
</html>

welcome.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP</title>
    </head>
    <body bgcolor="cyan">
      <center>
          <h1>*****Student Information System*****</h1>
          </center>
          <br>
          <br>
        <h3>Welcome Admin!</h3>
        
    </body>
</html>

I have a database named as mydb where there is a table named user having username is admin and password is admin@123. So, in the code where I should make change to load the welcome.jsp page. Expecting a reply from you. Thanking you

With regards
Kox
 
Dave Tolls
Ranch Hand
Posts: 2563
27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, your form should be submitting to a servlet, not a JSP page.
That way you can remove all the Java code in that JSP page.  There shouldn't be any in a JSP.

If you're not being redirected where you expect, then the issue lies with the LoginWorker.
It is returning an incorrect value.

Try debugging it by logging the values from the request, and the result value returned.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!