Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Input Validation Error

    Hi there,

    I was trying an input validation example taken from the OWASP ESAPI and I am getting the following error:

    Error: Cannot make a static reference to the non-static method getValidInput(String, String, String, int, boolean) from the type Validator

    Html:

    Java Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    	<form method="post" action="inputvalidation">
    		Enter zip:<input type="text" name="zip" />
    	</form>
    </body>
    </html>

    Servlet

    Java Code:
    package com.example.web;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import org.owasp.esapi.*;
    import org.owasp.esapi.errors.ValidationException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class InputValidation extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
        public InputValidation() {
            super();
            // TODO Auto-generated constructor stub
        }
    
    
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		response.setContentType("text/html");
    		PrintWriter out=response.getWriter();
    
    		
    		try
    		{
    			 String zipCode=Validator.getValidInput("ChangeAddressPage_ZipCodeField",
                             request.getParameter( "zip" ), 
                              "zipCodePattern", 10, false); //Error on this line 
    			 out.print(zipCode);
    				 
    		}
    		catch(ValidationException e)
    		{
    			response.sendError( response.SC_BAD_REQUEST, e.getMessage() );
    		}
    	}
    
    }
    Any suggestions?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default Re: Input Validation Error

    Cannot make a static reference to the non-static method
    Create an instance or get a reference to the class and use that reference to call the method.
    Or make the method static

    This syntax: CLASSNAME.methodName is a static refererence.

Similar Threads

  1. Input validation help
    By AdamG in forum New To Java
    Replies: 3
    Last Post: 10-17-2011, 09:29 PM
  2. Input Validation Help
    By Spyderpig in forum New To Java
    Replies: 3
    Last Post: 02-18-2011, 11:58 AM
  3. JTable input validation
    By Manfizy in forum New To Java
    Replies: 10
    Last Post: 06-10-2009, 09:04 AM
  4. Input Validation
    By kickflipper1087 in forum New To Java
    Replies: 5
    Last Post: 11-03-2008, 05:47 AM

Posting Permissions

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