Results 1 to 2 of 2
  1. #1
    drw4d is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default Import packages in JSP

    I am working in JSP (NetBeans 7.0.1), and need to import a utility that I have created (CalHelp.java within a source package I created). I have the Import statement set up, but there's still something not working. In order to call a method from my utility, I need to pre-append the class name.

    Here are two examples (in a snippet of the code). The first line here is the import statement. In the first case (daysInMonth), I am not pre-appending, and the compiler doesn't like it. In the second (dayOfWeek), I do pre-append the class, and everything seems to be okay. If I add CalHelp. to the daysInMonth method call, it works fine too.

    Anyone have any thoughts on what I am doing wrong, that I need to pre-append the class name on my method calls?


    Java Code:
            <%@ page import="CalUtils.CalHelp" %>   
     
                 <% 
                
              ... more code here ...
    
                int monthDays = daysInMonth(mm, yy);
                int blankDays = CalHelp.dayOfWeek(mm, 1, yy);
    
              ... more code here ...
    
              %>

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Import packages in JSP

    It's no different to normal Java code (since that is what it is).
    You still need to give it the class name.
    Java Code:
    import java.util.Math; // Note this is for the purposes of the example and you would not need this.
    public class MyClass {
        public double someMethod() {
            return Math.ceil(someDouble);
        }
    }

Similar Threads

  1. how to import packages files to my applet in netbean
    By funkygarzon in forum Java Applets
    Replies: 4
    Last Post: 08-16-2010, 07:02 PM
  2. confused about packages and import
    By nttaylor in forum New To Java
    Replies: 7
    Last Post: 12-14-2009, 05:55 AM
  3. still confused about packages and import
    By nttaylor in forum New To Java
    Replies: 1
    Last Post: 12-13-2009, 10:27 PM
  4. import packages
    By gregorio99 in forum New To Java
    Replies: 3
    Last Post: 11-06-2009, 12:43 PM
  5. Problems with packages (import statements)
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 06-29-2007, 11:57 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
  •