0

I am using Tomcat6.0, Eclipse SDE 7.0 Express for Web Developers, and jdk1.6

In my jsp page i have a code that looks like the followeing

<%
List<String> options = new ArrayList<String>();
DynamicCombo comboBox = new DynamicCombo();
options = comboBox.generateComboBox();
Collections.sort(options);
int tempVar = 0;
while (tempVar < options.size()) {
out.print("<option value=\"");
out.print(options.get(tempVar));
out.print("\">");
out.print(options.get(tempVar));
out.print("</option>");
tempVar++;
}
%>

DynamicCombo is a class inside the package com.ems.billGen.util and i am importing this package in the jsp appropriately as :-

<%@page import="com.ems.billGen.util.*" %>

This class DynamicCombo has a method named generateComboBox(), that simply creates a list of strings and returns this string.

When I hover over the class DynamicCombo in the above jsp, i realize that it is well recognized because i get the proper documentation for the class. Please see the screen shot below :- on hovering over the class name in the jsp file

Now when i deploy the above page and view it in firefox, i get the following jasper exception :-

An error occurred at line: 36 in the jsp file: /implementation.jsp

DynamicCombo cannot be resolved to a type
33:     <td><select name="product_list">
34:         <%
35:             List<String> options = new ArrayList<String>();
36:             DynamicCombo co = new DynamicCombo();
37:             options = co.generateComboBox();
38:             Collections.sort(options);
39:             int tempVar = 0;

I am not able to understand the reason, and how to solve this issue. Any inputs are appreciated.

The respective class file is also being generated for DynamicCombo in the web-inf folder of the war file as:- class file is actually present in the generated war file

qre0ct
  • 5,680
  • 10
  • 50
  • 86
  • The error message is clear. Maybe you have a typo or your class isn't in that package. By the way, you should refactor your code to stop using scriptlets. Please read [How to avoid Java Code in JSP-Files?](http://stackoverflow.com/q/3177733/1065197) – Luiggi Mendoza Feb 15 '13 at 06:37
  • Thanks for the reply..Yes in do understand that the error message is clear. But the reason is not. Because i am sure there is no typo. And also as i mentioned above, i have taken care that the class is in the respective package which i am importing. Thanks for the suggestion though. I am going through the link you provided. – qre0ct Feb 15 '13 at 06:41
  • Maybe your class isn't there, you should check the classes in the generated war file (not in your project). – Luiggi Mendoza Feb 15 '13 at 06:44
  • ok. It would be great if you could please let me know how to check the classes in the war file? The war file, i guess, can't just be opened to look in for the available classes.And also i am actually creating the war file using all the classes present in my project. So i guess definitely the war file should contain all the required classes from the respective libraries. – qre0ct Feb 15 '13 at 06:55
  • Change the name of your file from *myWebProject.war* to *myWebProject.zip*,uncompress it and you will get all the folder structure of your web project. Navigate to the *WEB-INF/classes* folder and you'll see the compiled java classes *className.class* for your project. Check if there's a *DynamicCombo.class* file under *com/ems/billGen/util*. Note that if this class in in a jar and not directly in your web project, you can get the jar where it must be and do the same process. – Luiggi Mendoza Feb 15 '13 at 06:58
  • thanks for the wonderful response. let me check and let you know if this analysis solves the issue. – qre0ct Feb 15 '13 at 07:05
  • Strangely it is present there, the DynamicCombo class file is present there. Please chk the original post to see the screenshot of the same. – qre0ct Feb 15 '13 at 07:18
  • Just to made a test, write the full name of the class when using it: `com.ems.billGen.util.DynamicCombo co = new com.ems.billGen.util.DynamicCombo(); //rest of code`, recompile and test if it works (it should, by the way) or if you get an error elsewhere in the page. – Luiggi Mendoza Feb 15 '13 at 07:24
  • yeah i tried that as well... in fact that was the first thing i tried.... but no use. Even that could not solve the issue. – qre0ct Feb 15 '13 at 07:38

1 Answers1

3

The error message says it all, and the screenshot confirms: such class does not exist in the right path.

The problem is subtle: you import com.ems.billGen.util.DynamicCombo, and the path to the class is com/ems/billgen/util/DynamicCombo.class (notice the capital G in package name and the lack thereof in the path name).

Probably it is an error of some of the tooling. The error was triggered by the fact that the naming does not follow Java conventions (which is never to use capital letters in package names).

fdreger
  • 12,264
  • 1
  • 36
  • 42
  • +1: This just proves some of the big errors you can make when using scriptlets in JSP. – Luiggi Mendoza Feb 15 '13 at 07:41
  • @LuiggiMendoza: hmmm... thanks for the +1, but in the case of this specific error I fail to see how writing would make the mistake more visible than <%@page import="com.ems.billGen.util.DynamicCombo" %>? It looks practically the same... – fdreger Feb 15 '13 at 07:49
  • Indeed you can process the data from the `DynamicCombo` in the servlet and save the sorted list as a request attribute, then use `` to fill the dropdownlist. Note that with this, there's no need to use `` tag :) – Luiggi Mendoza Feb 15 '13 at 07:51
  • @LuiggiMendoza: well.. if it was an IDE error, setting the value in a servlet would not have helped. And if it was a mere typo, then it would actually be WORSE! scriptlets and beans are statically typed, so their validity can be checked before deployment. Values set in servlet are not discoverable in any static way - so any typos are much harder to detect :-) – fdreger Feb 15 '13 at 15:16