Results 1 to 5 of 5
  1. #1
    fox is offline Member
    Join Date
    May 2010
    Rep Power

    Default Login page problem

    i have a problem in login page.
    After running program, in the first click to submit buttom there is a problem like following
    HTTP Status 500 -

    type Exception report


    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.


    org.apache.jasper.JasperException: java.lang.NullPointerException

    root cause


    note The full stack traces of the exception and its root causes are available in the Sun GlassFish Enterprise Server v2.1 logs.
    Sun GlassFish Enterprise Server v2.1

    ================================================== =

    in the second try or refreshing page, it is working right
    it happens both glassfish and tomcat.

    What will be the problem???

    <%! String username;%>
    <%! String password;%>
    <%! String role;%>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.sql.Date" %>
    <%@ page import="*" %>
    <%@ page language = "java" %>
    try {
    String url = "jdbc:mysql://localhost:3306/music";
    Connection connect = DriverManager.getConnection(url, "root", "");
    Statement state;
    state = connect.createStatement();

    String strQuery1 = "select Password, Role from Login_Info where User_name='" + username + "'";

    username = request.getParameter("username");
    password = request.getParameter("password");

    ResultSet result = state.executeQuery(strQuery1);
    String pass;
    String user = "user";
    while ( {
    pass = result.getString("Password");
    role = result.getString("Role");

    role = role.trim();
    if ((pass.equals(password)) && (role.equals("user"))) {
    role = "user";
    session.setAttribute("username", username);
    } else if ((pass.equals(password)) && (role.equals("admin"))) {
    role = "admin";
    } catch (SQLException e) {
    System.out.println("SQL Exception: " + e.toString());
    } catch (ClassNotFoundException cE) {
    System.out.println("Class Not Found Exception: " + cE.toString());
    role = role.trim();
    if (role.equals("user")) {%>
    <jsp:forward page="user/userhomepage.jsp" />

    <%} else if (role.equals("admin")) {
    <jsp:forward page="admin_home_page.html"/>
    <%} else
    out.println("<p><font face=\"Arial\" size=\"2\" color=\"#800000\"><b>You have entered incorrect logon information. Please enter correct logon details.</b></font> </p>");
    <p><font face="Arial" size="2" color="#800000">Please enter your logon details.</font> </p>
    <p><font face="Arial" size="2" color="#800000">User Name :</font> <input type="text" name="username" size="20"></p>
    <p><font face="Arial" size="2" color="#800000">Password :</font>&nbsp;&nbsp; <input type="password" name="password" size="20"></p>
    <p><font face="Arial" size="2" color="#800000">New User? <a HREF=" http://localhost:8081/music-war/RegisterPage.html">Register</a></font></p>
    <p align="center"><input type="submit" value="Submit" name="B1"><input type="reset" value="Clear" name="B2"></p>

  2. #2
    kafrlust is offline Member
    Join Date
    May 2010
    Rep Power


    you probably get null pointer exception because one of your variables in null and you call a method.Perhaps if you take a look at the full stack trace, you will find the line of code that has the problem! :)

  3. #3
    flyfisherman is offline Member
    Join Date
    Mar 2010
    Rep Power


    is it hard to use code tags ?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Quote Originally Posted by flyfisherman View Post
    is it hard to use code tags ?
    For first-time posters it is. To the original poster, please read the link in my signature about using code tags as it will make your code posted in the forum much easier to read, and this will increase your chances of getting good help (which you're not going to get from me as I know zilch about JSP).

    Much luck!

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    A few suggestions, which might make it easier for you to see what's gone wrong (though looking at the stack trace is always a good start).

    Almost all this, bar the actual display code, should be part of a Servlet, with the databsse code in its own database layer (usually some sort of DAO). JSPs should be all about displaying stuff.

    Secondly, the password should be part of the SQL query. And it shouldn't be returned by that query. So it'll be checking both the user name and the password. If a role comes back then they've successfully logged on, if not then they haven't.

    Finally, with the removal of your checks of the password in Java, you now no longer need to assign stuff to role (not that you did anyway).

Similar Threads

  1. login page
    By banie in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-09-2008, 08:37 AM
  2. JSP login page
    By banie in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-06-2008, 04:23 AM
  3. login page
    By keerthi_y19 in forum New To Java
    Replies: 9
    Last Post: 08-06-2008, 11:58 AM
  4. Login page
    By banie in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-03-2008, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts