So, after searching the web for a few hours, I decided to post my question here:
I'm writing a web project , running it on tomcat Apache through Xampp (a program that runs servers).
I wrote a java file called "MyConnection" that establishes a connection to a mysql database and does all kinds of other things.The file is in package java_files.
I need to import said file to a jsp file called "login" so that I can send user and password to the database to check if they are correct.
I tried to import the java file using all kinds of options -
<%@ page import="java_files.MyConnection"%>
and then:
<%
MyConnection myCon = new MyConnection();
%>
but it just gives me a "could not resolve to a type" error
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file: [C:\xampp\tomcat\work\Catalina\localhost\targil1_facebook\org\apache\jsp\WebContent\login_jsp.java]
Only a type can be imported. java_files.MyConnection resolves to a package
An error occurred at line: 18 in the jsp file: /WebContent/login.jsp
MyConnection cannot be resolved to a type
15:
16:
17: <%
18: MyConnection myCon = new MyConnection();
19:
20: %>
21:
I could not find any working solution. I tried:
1.cleaning the project
2.set output build folder to Web-Inf (there is a MyContent.class file in the folder under "java_file" folder which cannot be seen from the eclipse project explorer but I can see it if I open it in a folder)
3.running the project with Apache tomcat in eclipse
4.various options of import strings (with package name/ without , * instead of class name and so on)
and I cannot make it work!
Please, help me find a solution!!!
Thank you!
Copyright Notice:Content Author:「Alex K」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34833516/importing-java-file-to-jsp-cannot-be-resolved-to-a-type-error