tags:

views:

23

answers:

2

Hi,

I had all my servlets and classes in the default package. I have created these and JSP's and its all working fine.

However i want to import some of the classes into the JSP's so i moved all the classes and servelts into a new package called Driver. I did not change any code anywhere, just moved it into a new package. The application compiles just fine.

Now i cant seem to access any of my classes or servlets, any ideas?

javax.servlet.ServletException: Wrapper cannot find servlet class Driver.viewTrip or a class it depends on
+1  A: 
  • check whether the correct class files and package structure is reflected in your servlet-container (tomcat) - i.e. whether in WEB-INF/classes everything is correct.

  • don't write business-logic in jsps. Ideally, you shouldn't need to import anything in your jsps. As explained by BalusC in the comments, this can be done in a few steps

    1. in your servlet call request.setAttribute("attributeName", value);
    2. forward to the jsp - getServletContext().getRequestDispatcher("yourView.jsp").forward()
    3. in your .jsp use the value that was set in the attribute (instead of obtaining it with business logic in the jsp itself)
  • use lowercase for package names

Bozho
How do i check WEB-INF/classes ?
Taylor
@Taylor go to your tomcat/webapps/webapp folder. How are you deploying your app?
Bozho
It seemed to work fine now that i have refactored it with a lower case package name, thankyou!
Taylor
@Taylor here on SO, if an answer has worked for you, you are invited to mark it as accepted (there is a tick below the vote counter)
Bozho
+1 for no business logic in JSP. Taylor: let a servlet put data as request/session attribute, forward the request to a JSP and use taglibs/EL in JSP to access it.
BalusC
A: 

Make sure that you defined the package at the top of all your java files.

For example "src/Driver/viewTrip.java" would like like the following:

package Driver;

public class viewTrip {
    // ...
}

Take a look at Creating and Using Packages. I also highly recommend you to read the "Java Code Conventions". Since I am a new user, therefore I am only allowed to post one hyperlink so the link to the code conventions is (http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html)