Importing java file to jsp - cannot be resolved to a type error
NickName:Alex K Ask DateTime:2016-01-17T07:56:36

Importing java file to jsp - cannot be resolved to a type error

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

More about “Importing java file to jsp - cannot be resolved to a type error” related questions

Importing java file to jsp - cannot be resolved to a type error

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 jav...

Show Detail

Importing java class to jsp causing cannot be resolved to a type error

JSP code: &lt;%@ page import = "action.LoginCheckAction" %&gt; &lt;% String username = request.getParameter("username"); String password = request.getParameter("password"); Lo

Show Detail

class cannot be resolved to a type(jsp)

I am new to jsp. I was learning useBean method, and there is a example at http://www.studytonight.com/jsp/getproperty-tag.php Scroll down, you will find it. Here is my jsp file: &lt;html&gt; &lt;

Show Detail

Statement cannot be resolved to a type in JSP File

While running Pregister.jsp file it showing follwing An error occurred at line: 31 in the jsp file: /pregister.jsp Statement cannot be resolved to a type PreparedStatement cannot be resolved to a ...

Show Detail

HTTP Status 500 - Unable to compile class for JSP: import cannot be resolved to a type

The following is my code in a jsp file : int s_id = session.getAttribute("s_id") != null ? ((Integer) session.getAttribute("s_id")).intValue() : 0 ; String Pending = "Pending"; %&gt; &lt;!-- &

Show Detail

<jsp:useBean> error: Bean cannot be resolved to a type

I was trying to see how Javabeans work, so I created a simple JSP project which has InfoRet.java (Javabean) and a JSP file to retrieve values from the bean. This is the code: public class InfoRet

Show Detail

Importing a class in a JSP file

I wrote some code as a Java Servlet and now I am trying to convert it to a JSP. I wrote a class in a separate file which I was using, and I can't figure out how to get the JSP file to recognize the...

Show Detail

JSP compile error: Arrays cannot be resolved

My environment is JDK 1.6, Eclipse Indigo, JBoss 4.2.3.GA-jdk6. In Eclipse Windows --> Preferences, then in Java --> Compiler section the Compiler compliance level is set to 1.6. In one JSP I am

Show Detail

How to use a Java class in JSP scriptlet? Error says the class cannot be resolved to a type

I have written a sample JSP file in Eclipse and a Java file and was trying to call the Java class inside my JSP but it is not working. The code of the JAVA file is as follows: TestJava.jva public...

Show Detail

How to use a Java class in JSP scriptlet? Error says the class cannot be resolved to a type

I have written a sample JSP file in Eclipse and a Java file and was trying to call the Java class inside my JSP but it is not working. The code of the JAVA file is as follows: TestJava.jva public...

Show Detail