Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP strange problem

 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
as I've already introduces before, I try to call a jar file thru jsp page.
The problem is that I can't invoke a method in my class that in the jar.
I get this error:

org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 14 in the jsp file: /test.jsp
hasp_demo cannot be resolved

11: </head>
12: <body>
13:
14: <%=hasp_demo.CheckFlow() %>
15: </body>
16: </html>

If someone could give me a hint... thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JSP.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP is translated into a servlet. Just as you can't call random code in a servlet, you can't call random code in a JSP.

Not that you should be using Java code like this in JSPs anyway.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this. How can we help you if you don't give us any info to go on?

How is hasp_demo declared?
 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
so here is the all data (I'm using Eclipse) :

1. I developed a class with a static method. The method is called "CheckFlow()" and returns String.
That class is using another jar files and dlls, that located inside the same project.
I put that class in a new package called "Hasp" (not in the default package), made it public class, and
gave it a name begining with Capital letter - HaspDemo.

2. I generated out of the project that contains that class a jar, called hasp.jar.

3. I created a new web project called HaspWeb. I creates a jsp file in it: test.jsp.

4. In the web project's properties , in the "Java build path" window I added to the class path the hasp.jar - the jar that I created,
after copying it from the place that I creates it to the HaspWeb\WebContent\WEB-INF\lib folder. I added it to the class path from
this location.

5. In my jsp file this is my very simple code: (I remind you that CheckFlow() is a static method):

<%@page import="Hasp.HaspDemo"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%= Hasp.HaspDemo.CheckFlow() %>
</body>
</html>

6. I'm getting the exception of:

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

An error occurred at line: 6 in the generated java file
Only a type can be imported. Hasp.HaspDemo resolves to a package

An error occurred at line: 13 in the jsp file: /test.jsp
Hasp.HaspDemo cannot be resolved to a type
10: <title>Insert title here</title>
11: </head>
12: <body>
13: <%= Hasp.HaspDemo.CheckFlow() %>
14: </body>
15: </html>

7. Thanks for any help.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing I'd look at is the first error.

Well, *really* the first thing I'd look at is your package naming convention, but that, at least, won't cause an error.
 
Chinmaya Chowdary
Ranch Hand
Posts: 432
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Moshi.
after copying it from the place that I creates it to the HaspWeb\WebContent\WEB-INF\lib folder

Here 'HashWeb' is your application context. 'WEB-INF' must be directly inside 'HashWeb'.
 
cow clarke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean that you have a common class package, and you would like to import it into JSP file, or you've just needs to produce a java file only for the project, which means , you just needs to put your .class file into WEB-INF/classes.

So, it would be good to state your problem more clearly.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"cow clarke", please read this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic