Results 1 to 6 of 6
  1. #1
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default JSP validation error

    I have a form with username, password and captcha code.
    when I entered nothing (it's successfully return the not=1), but when I entered all of the field, it returns :
    Error :
    org.apache.jasper.JasperException: An exception occurred processing JSP page /action/doLogin.jsp at line 7

    4: String security_code = request.getParameter("security_code");
    5: String key = (String)session.getAttribute("key");
    6:
    7: if(username.equals("") || password.equals("") || security_code.equals("")){
    8: response.sendRedirect("../index.jsp?not=1");
    9: return;
    10: }
    It's so confusing..
    this is my doLogin.jsp

    doLogin.jsp
    Java Code:
    <%
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      String security_code = request.getParameter("security_code");
      String key = (String)session.getAttribute("key"); //my session for captcha
      
      if(username.equals("") || password.equals("") || security_code.equals("")){
      	response.sendRedirect("../index.jsp?not=1");
    	return;
      }
      else if(key.compareTo(security_code)==0){
      	response.sendRedirect("../index.jsp?not=2");
    	return;
      }
    %>
    Thanks for your help

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    it's possible if the username, key , and session are not set, or missing from teh request and session,
    that these would be null, which generates that NullPointerException on line 7.

    for strings [read from a request parameter, session variable], we always need to test if they are not null first
    [code]
    if( (username == null || username.equals(""))
    || (password == null || password.equals(""))
    || (security_code == null || security_code.equals(""))
    ) {
    [code]

  3. #3
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    thanks palz, it's solved..
    i see..so it needs to know whether it is null or not.

    thanks ^^

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Do yourself a favor and remove all that Java code from the JSPs. JSPs are ideal for display (view) not controlling application logic. This is not 1998.

  5. #5
    sysout is offline Member
    Join Date
    Aug 2009
    Posts
    66
    Rep Power
    0

    Default

    Java Code:
    String userLogin = (String) session.getAttribute("userLogin");
    	String user = (String) session.getAttribute("user");
    	if( (userLogin == null || userLogin.equals("")) || (user == null || user.equals("")) || (userLogin == null || !userLogin.equals("ADMIN")) || (userLogin == null || !userLogin.equals("OPERATOR"))){
    		response.sendRedirect("../login.jsp?not=8");
    		return;
    	}
    it always sendRedirect to not=8;

    if change to this :
    if( (userLogin == null || userLogin.equals("")) || (user == null || user.equals("")))
    it works perfectly, but it doesn't validate for the user privileges.

    @r035198x : what do you mean, palz? can you tell us more spesifically?

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

Similar Threads

  1. VAlidation
    By chetna1982 in forum New To Java
    Replies: 2
    Last Post: 12-11-2008, 07:08 AM
  2. Struts validation
    By Jack in forum Web Frameworks
    Replies: 3
    Last Post: 10-06-2008, 12:54 AM
  3. Swing Validation
    By ppayal in forum AWT / Swing
    Replies: 0
    Last Post: 02-09-2008, 09:00 AM
  4. Swing validation
    By ppayal in forum New To Java
    Replies: 0
    Last Post: 02-09-2008, 08:59 AM
  5. Another Query On Validation
    By Albert in forum Web Frameworks
    Replies: 1
    Last Post: 07-05-2007, 06:47 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
  •