java class in jsp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • game2d
    New Member
    • Apr 2013
    • 59

    java class in jsp

    i have a jsp file below. in tere i want to create java methods to test if its number or not etcc... so my plan is to make a java class and put all my methods in there. i need some help importing the java file in jsp.

    i am getting error on line:
    <%@ page import = "JavaFuncti ons" %>


    index.jsp
    Code:
    <%@ page import = "JavaFunctions" %>
    <html>
    <body>
    	
         <form method="post" action="index.jsp">
    		what's your name?<br/>
    		<input type="text" name="usernameField"/><br/>
    		what's your aga?<br/>
    		<input type="text" name="ageField" /><br/>
    		<input type="submit" name="submit" />
    	</form>
    
    	<%
    		if (request.getParameter("submit") != null) {
    			
    			String username = request.getParameter("usernameField");
    			
    			String number1 = request.getParameter("ageField");
    	
    			//check errors
    			if(username.equals(""))
    			{
    				out.print("Error enter name");
    			}
    			else if(number1.equals(""))
    			{
    				out.print("Error enter age");
    			}
    			else
    			{
    				int number1I = Integer.parseInt(request.getParameter("ageField"));
    				out.print("answer" + number1I);
    			}
    		}
    	%>
    	
    </body>
    </html>



    Code:
    public class JavaFunctions {
    
    	public JavaFunctions() {
    		// TODO Auto-generated constructor stub
    	}
    
    	public static boolean isNumber(String str)
    	{
    		try
    		{
    			int num = Integer.parseInt(str);
    		}
    		catch(NumberFormatException e)
    		{
    			return false;
    		}
    		return true;
    	}
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What was the error message? If the class is in a package (you should always put your classes in your own package) then you need to import using the fully qualified name i.e including the package name.

    Comment

    Working...