0

Import statement for user defined package/class gives compile error and browser error. Same import statement works fine for java packages but not other. I have a simple jsp file in which I am only trying to import a java class I made to test. The jave class is created under src and in a package: src->org.easy->TryThis.java. The jsp file runs without any issues if I import any java util package but the moment I try to import my own package.class. It give me error 500 http - unable to compile and on the console it says "TryThis cannot be resolved to a type" : "TryThis is my class". I tried pasting jar file in web-inf lib, I tried many other solutions from different forums but nothing works. When making the import statement, it lets me auto fill the path to my java class though as if it can read my class in the path. The closest I got it to working is if in the import statement I say "<%@ page import="org.easy.*" %>, the errors vanishes on browser and console but if I try to then access the class and use its fields than errors come back. Can someone help... Thank you in advance

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<!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>
<!-- This class will show how to import packages and classes -->
<!-- 1. importing a  package -->
<%@ page import="org.easy.TryThis" %>
<% out.println(""); %>
</body>
</html>
HKM
  • 1
  • 3
  • Does this answer your question? [How do you import classes in JSP?](https://stackoverflow.com/questions/239147/how-do-you-import-classes-in-jsp) – mohammedkhan Aug 12 '20 at 08:59
  • No it doesn't at all. That page shows how to do an import statement... in my case my import state is not working giving errors, this is only happening trying to import user defined package and class. – HKM Aug 13 '20 at 03:15

1 Answers1

0

The problem was in project facet that no forum is talking about. For some reason mine was at a lower version while my projects where using java se 1.8. I changed it to 1.8 and it all the errors went away.... if someone else is having same issues with compile time error "package name of not type" you have to go build path and click on project facets and then where java is choose the exact same version 1.7 if your jre is 1.7, for me it was 1.8... and eclipse doesn't make this change for you automatically. It will let your projects be 1.8 and facet at 1.5... which causes errors

HKM
  • 1
  • 3