0

I have a jsp file that imports from my package folder inside my classes directory. When I try to use it, i get the "Unable to compile" and "cannot be resolved to a type" errors. Here are my code.

<%@ page language="java" import="cs5530.*" %>
<html>
<head>
<script type="text/javascript">
function showInvalid()
{
    document.getElementById("invalid").style.display = 'block';
    document.getElementById("loginForm").reset();
}
</script>
</head>
<body>
<p>Welcome to FlixNet. Sign In</p>
<form name="loginForm" method="post" action="index.jsp">
    User Name: <input type="text" name="username"><br>
    Password: <input type="Password" name="password"><br>
    <input type="submit" value="Submit">
    <div id="invalid" style="display:none">
        <p>Invalid username or password</p>
    </div>
</form>
<%
Connector con = new Connector();
con.closeConnection();
%>
</body>
</html>

this is the error

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 23 in the jsp file: /index.jsp
Connector cannot be resolved to a type
20:     </div>
21: </form>
22: <%
23: Connector con = new Connector();
24: con.closeConnection();
25: %>
26: </body>


An error occurred at line: 23 in the jsp file: /index.jsp
Connector cannot be resolved to a type
20:     </div>
21: </form>
22: <%
23: Connector con = new Connector();
24: con.closeConnection();
25: %>
26: </body>


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

this is my file structure

public_html
    index.jsp
    |WEB-INF
        |classes
             mysql.jar
            |cs5530
                Connector.java
                Connector.class
                other java and class files.

my Connector class is under the package cs5530 so that isn't the issue. The connector class is a simple db connector class that I have tested and it works.

Bibodha
  • 51
  • 1
  • 1
  • 7

6 Answers6

1

copy the jar in WEB-INF/lib/ directory and then restart your web container

Gaurav Sharma
  • 745
  • 7
  • 23
0

Please check whether Connector.class is really imported. It looks like that you have not imported it.

UVM
  • 9,776
  • 6
  • 41
  • 66
0

Try

<%@ page import="cs5530.*" %>
Jaydeep Rajput
  • 3,605
  • 17
  • 35
0

This was a result of me not being in charge of my Tomcat server. Apparently it needs to be cleaned if something major changes. My code was spotless.

Bibodha
  • 51
  • 1
  • 1
  • 7
  • But your question had dark spots ;) – AllTooSir Apr 13 '13 at 07:27
  • This might be a separate thread, but I don't understand what the "Tomcat server" has to do with a compile error. Can someone explain that? I am seeing the same error. I thought that the Eclipse IDE compiler would be separate from the server. The server wouldn't even see the code until i drop in the compiled jar file. ??? – Baruch Atta Aug 20 '15 at 18:08
0

This is because the xxx.jar file that describes the package you're trying to import has to be directly in the lib folder. e.g.: WebContent/WEB-INF/lib/xxx.jar. If it can only find the package folder inside the /lib then even though your .jar is inside this package folder that is still enough to create the error that it can only resolve to a 'package' and cannot resolve to a 'type'.

0

You are missing imports at top of your .jsp file:

<%@ page import="packageWhatever.packageWhatever.ClassName" %>

Simplified example of problem:

JSP FILE:

TOMCAT_PRJ_DIR\src\main\webapp\index.jsp

WRONG:

<html><body><h1> 
    <%= Main.TEST_FUNCTION() %>
</h1></body></html>

CORRECT:

<%@ page import="launch.Main" %>
<html><body><h1> 
    <%= Main.TEST_FUNCTION() %>
</h1></body></html>

FILE BEING IMPORTED:

TOMCAT_PRJ_DIR\src\main\java\launch\Main.java

package launch;
.... imports here ....

public class Main {

    public static final String
    TEST_FUNCTION(){
        return( "[TEST_FUNCTION]" );
    };

    ...other code...   
};

Stack Used: Java+Tomcat+Maven

KANJICODER
  • 3,611
  • 30
  • 17