HTTP Status 500 - Unable to compile class for JSP Java8, Tomcat8.5
Asked Answered
S

1

0

I have a main jsp file which makes use of java class in the boxers package. But when I try to run jsp, the following error occures: HTTP Status 500 - Unable to compile class for JSP:in the jsp file: /web/date_info.jsp boxers.B cannot be resolved to a type.

date_info.jsp

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <p><%= boxers.B.voice()%></p>

    </body>
</html>

B class:

 package boxers;


public class B {
    public static String voice()
    {
        return "HELLO";
    }
}

I've read the conflict between versions can cause this; my Java version is 8, Tomcat 8.5..

I've looked into webapps/my_app/build/web/WEB-INF/classes/boxers folder and there is a B.class file...

EDIT: I wonder if those who downvote at least know the answer to the question.

Samaniego answered 9/9, 2016 at 16:8 Comment(17)
try importing the package boxers in your jsp page like <%@ page import="boxers" %> then you can access the class without specifying the packageArquebus
boxers.B cannot be resolved to a type is like searchnig for a class named boxers and within it a property called BArquebus
@El Sam I can't import only boxers - netbeans requires '.'. Importing <%@ page import="boxers.*" %> and using B.voice() doesn't change things..B cannot be resolvedSamaniego
Ok, import the class B <%@ page import="boxers.B" %> and then you can call voice() directlyArquebus
@El Sam Netbeans highlights it - can't find the method without B or boxers.B before it..Samaniego
oops, i meant B.voice()Arquebus
@El Sam B cannot be resolved An error occurred at line: 36 ; 36: <p><%= B.voice()%></p>Samaniego
The problem was the = , it's only used when you want to print a variable, instead you want to call a method and to do it you only use the scriptlet , i.e <% someMethod();%>Arquebus
@El Sam Now, when I <p><% B.voice();%></p> the <%@ page import="boxers.B" %> usddenly causes error - Only a type can be imported. boxers.B resolves to a package. When I replace it with %@ page import="boxers.*" %> it gives an old thing: An error occurred at line: 35 in the jsp file: /web/date_info.jsp B cannot be resolved, 35: <p><% B.voice();%></p>Samaniego
you must keep the class import <%@ page import="boxers.B" %>, for the scriptlet , try this <% String msg = B.voice();%> <%=msg%>Arquebus
@El Sam An error occurred at line: 35 in the jsp file: /web/date_info.jsp B cannot be resolved 35: <p><% String msg = B.voice();%></p> and import: An error occurred at line: [14] in the generated java file Only a type can be imported. boxers.B resolves to a package It sucks(Samaniego
This error is really getting ridiculous, I found a solution on SO, try this <%@ page import="boxers.B;" %> notice the semicolon after BArquebus
@El Sam HTTP Status 500 - Unable to compile class for JSP remained, but there is no word about B class or boxers package, only exception and root cause things, which were present before. PS Do you have Netbeans&Tomcat? If yes. does my initial example work for you? I begin to contemplate reinstalling everything..Samaniego
In which line does the root cause lie ? for my java,JavaEE projects , I sue Intellij, and yes I have Tomcat. I recommend you to remove the static from the method and create an instance of you class like so <% String msg = new B.voice();%>Arquebus
No line. Just java.lang.IllegalArgumentException: Page directive: invalid value for import... I googled it, looks like the semicolon causes it.. Tried non-static method out. It's all the same. With semicolon - gives the abovementioned exception, without - Only a type can be imported. boxers.B resolves to a package and An error occurred at line: 36 in the jsp file: /web/date_info.jsp B cannot be resolved to a type 35: <%! 36: B e=new B(); 37: %> 38: 39: <p><% String msg = e.voice();%></p>Samaniego
this is definitely not a JSP problem, it has to do with your netbeans+tomcat , I recommend you delete these files, clean, create others. check this thread, it has a lot of possible answers same problemArquebus
@El Sam I'll check it out. Thanks for your efforts..Samaniego
S
1

Figured it out. The application wasn't deployed correctly. The deployment process, described here helped me out. In particular - copying web application archive file (.war) and copying unpacked web application directory. My main mistake was that initially I applied the second method in the wrong way - copied all the folders in the app directory, created by Netbeans (build, src, web etc), while only NetbeansProjects/app_name/build/web's content should have been copied into tomcat/app_name/. Or just copy the war-file of NebeansProjects/app_name/dist/ into tomcat/webapps - the tomcat will create the appropriate folder with the files himself seconds later.

tl;dr: wrong deploment, copypaste war or web's content.

Samaniego answered 10/9, 2016 at 12:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.