By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

java class in jsp

P: 59
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 = "JavaFunctions" %>


index.jsp
Expand|Select|Wrap|Line Numbers
  1. <%@ page import = "JavaFunctions" %>
  2. <html>
  3. <body>
  4.  
  5.      <form method="post" action="index.jsp">
  6.         what's your name?<br/>
  7.         <input type="text" name="usernameField"/><br/>
  8.         what's your aga?<br/>
  9.         <input type="text" name="ageField" /><br/>
  10.         <input type="submit" name="submit" />
  11.     </form>
  12.  
  13.     <%
  14.         if (request.getParameter("submit") != null) {
  15.  
  16.             String username = request.getParameter("usernameField");
  17.  
  18.             String number1 = request.getParameter("ageField");
  19.  
  20.             //check errors
  21.             if(username.equals(""))
  22.             {
  23.                 out.print("Error enter name");
  24.             }
  25.             else if(number1.equals(""))
  26.             {
  27.                 out.print("Error enter age");
  28.             }
  29.             else
  30.             {
  31.                 int number1I = Integer.parseInt(request.getParameter("ageField"));
  32.                 out.print("answer" + number1I);
  33.             }
  34.         }
  35.     %>
  36.  
  37. </body>
  38. </html>



Expand|Select|Wrap|Line Numbers
  1. public class JavaFunctions {
  2.  
  3.     public JavaFunctions() {
  4.         // TODO Auto-generated constructor stub
  5.     }
  6.  
  7.     public static boolean isNumber(String str)
  8.     {
  9.         try
  10.         {
  11.             int num = Integer.parseInt(str);
  12.         }
  13.         catch(NumberFormatException e)
  14.         {
  15.             return false;
  16.         }
  17.         return true;
  18.     }
  19. }
Apr 16 '13 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
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.
Apr 17 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.