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.
boxers
in your jsp page like<%@ page import="boxers" %>
then you can access the class without specifying the package – Arquebusboxers.B cannot be resolved to a type
is like searchnig for a class namedboxers
and within it a property called B – Arquebus<%@ page import="boxers.*" %>
and usingB.voice()
doesn't change things..B cannot be resolved
– Samaniego<%@ page import="boxers.B" %>
and then you can callvoice()
directly – ArquebusB
orboxers.B
before it.. – SamaniegoB.voice()
– ArquebusB cannot be resolved
An error occurred at line: 36
;36: <p><%= B.voice()%></p>
– Samaniego=
, 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<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<%@ page import="boxers.B" %>
, for the scriptlet , try this<% String msg = B.voice();%> <%=msg%>
– ArquebusAn 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( – SamaniegoHTTP Status 500 - Unable to compile class for JSP
remained, but there is no word aboutB class
orboxers
package, onlyexception
androot 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.. – Samaniegoroot 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();%>
– Arquebusjava.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
andAn 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