Tomcat - java classes not being included in my jsp pages
I added a new Context in server.xml to move ROOT dir for my webapps, like so:
<Context path="" docBase="../sites" debug="0" reloadable="true" >
<Resource name="jdbc/myphoto" auth="Container" type="javax.sql.DataSource"
driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
url="jdbc:derby:C:\apache-tomcat-7.0.12\sites\webtech\WEB-INF\lib\photo"
maxActive="20" maxIdle="10" maxWait="-1" />
</Context>
Now for some reason, tomcat cannot find my custom java classes. My jsp page looks like so:
... some xhtml ...
<%@ page import="com.domain.webtech.Hello" %>
<%
Hello h = new Hello();
out.print(h.hello());
%>
And I can a Hello.java file in sites/webtech/WEB-INF/开发者_StackOverflow中文版classes/com/domain/webtech/ which is very simple:
package com.somename.webtech;
public class Hello {
public Hello() {
}
public String hello() {
return "hello, world!";
}
}
I compiled it and even packaged it into a webtech.jar file and placed it in sites/webtech/WEB-INF/lib/
Does anyone have any idea as to why Tomcat is not finding my classes?
Thanks for your time,
G.
Your docBase
has to point to the web root.
Change
<Context docBase="../sites" ...>
to
<Context docBase="../sites/webtech" ...>
And open your JSP by http://localhost:8080/page.jsp instead of http://localhost:8080/webtech/page.jsp.
精彩评论