title: How import a .java file into a JSP page?
body: <p>this is my first time trying to use java for backend web systems.</p>
  
  <p>I have been reading up some guides on how to do this, and thus far i understand the following points:</p>
  
  <ol>
  <li>I am not allowed to import .java files, but rather, import the class files.</li>
  <li>&lt;%@ page language="java" import="somefile.*"%>  this is how i import a package.</li>
  <li>After importing a package, I am required to create an instance of the class.</li>
  </ol>
  
  <p>However, I am confused with a few things.</p>
  
  <p>I now have a Dynamic Web Project, developing in Eclipse IDE and using TomCat7.0 apache.</p>
  
  <p>I have a directory
  Java_Resources/src/somepackage/</p>
  
  <p>and some .java files in the above directory.</p>
  
  <p>Question 1, in Eclipse, when I run these files, they are automatically compiled. Where does these class files go?</p>
  
  <p>Question 2, when I run the following code, I recieved some errors. What am I doing wrong? Is it because I do not have my class files in the right directory?</p>
  
  <pre><code>&lt;%@ page language="java" import="twitter.*"%&gt;
  
  &lt;%
      JavaFile jf = new Javafile();
  
      String result = jf.searchTweets("someString");
      System.out.println(result);
  %&gt;
  </code></pre>
  
  <p>Error report: </p>
  
  <pre><code>type Exception report
  
  message
  
  description The server encountered an internal error () that prevented it from fulfilling this request.
  
  exception
  
  org.apache.jasper.JasperException: An exception occurred processing JSP page /hello.jsp at line 10
  
  7: &lt;%@ page language="java" import="twitter.*"%&gt;
  8: 
  9: &lt;%
  10:     Javafile jf = new JavaFile();
  11:     
  12:     String result = jf.searchTweets("someString");
  13:     System.out.println(result);
  </code></pre>
  
  <p>Thank you for your time and effort.</p>
  
  <p>note: I have read the following links, but they do not seem to provide a solution on how to write your own .java files and import these classes into your jsp files.</p>
  
  <p><a href="http://www.jsptut.com/" rel="nofollow noreferrer">http://www.jsptut.com/</a></p>
  
  <p><a href="https://stackoverflow.com/questions/239147/how-do-you-import-classes-in-jsp">How do you import classes in JSP?</a> </p>
  
  <p><a href="http://www.coderanch.com/t/288534/JSP/java/importing-class-file-jsp" rel="nofollow noreferrer">http://www.coderanch.com/t/288534/JSP/java/importing-class-file-jsp</a></p>
  
  <p>EDIT: I found my own answer.</p>
  
  <p>This is my original directory</p>
  
  <p><img src="https://i.stack.imgur.com/yWaDQ.png" alt="enter image description here"></p>
  
  <p>As you can see, my WEB-INF/lib is empty.</p>
  
  <p>All that was required to do, is to move the relevant .jar files into this directory.</p>
  
  <p>Note: I have already imported the relevant .jar files to the Eclipse project, but it seems that I need to move them into WEB-INF/lib on top of importing them into the project.</p>
  
  <p>Thank you to all that helped answer my question.</p>
  
  <p>This is my final directory image<img src="https://i.stack.imgur.com/h0ddT.png" alt="enter image description here"></p>