JSP package problems
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
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
- in your servlet call
request.setAttribute("attributeName", value)
; - forward to the jsp -
getServletContext().getRequestDispatcher("yourView.jsp").forward()
- in your
.jsp
use the value that was set in the attribute (instead of obtaining it with business logic in the jsp itself)
- in your servlet call
use lowercase for package names
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)
精彩评论